From f9a95898d485c95c01c464e9e907cf0c9d80af89 Mon Sep 17 00:00:00 2001 From: Joby Elliott Date: Fri, 27 May 2022 10:44:41 -0600 Subject: [PATCH] Test overhaul (#2) * first attempt at PHPUnit tests in github actions * composer ignore platform deps * another try * plumbing * pdo auth * more plumbing * doing env variables right * will this work? * calling phpunit directly * don't specify test * export * bug fix * trying something * trying another thing * trying again * trying it right * might work this time * testing can't work on 7.0 --- .github/workflows/test.yml | 46 +++++++++++++++++++ .gitlab-ci.yml | 28 ----------- .travis.yml | 13 ------ README.md | 2 +- .../AbstractSQLDriverIntegrationTest.php | 31 +++++++++---- .../AbstractSQLDriverSchemaChangeTest.php | 31 +++++++++---- tests/Drivers/AbstractSQLDriverTest.php | 37 +++++++++++---- .../MariaDB/MariaDBDriverIntegrationTest.php | 33 +++++++++++-- .../MariaDB/MariaDBDriverSchemaChangeTest.php | 33 +++++++++++-- tests/Drivers/MariaDB/MariaDBDriverTest.php | 33 +++++++++++-- .../MySQL/MySQLDriverIntegrationTest.php | 33 +++++++++++-- .../MySQL/MySQLDriverSchemaChangeTest.php | 33 +++++++++++-- tests/Drivers/MySQL/MySQLDriverTest.php | 33 +++++++++++-- .../SQLite/SQLiteDriverIntegrationTest.php | 25 +++++++--- .../SQLite/SQLiteDriverSchemaChangeTest.php | 25 +++++++--- tests/Drivers/SQLite/SQLiteDriverTest.php | 25 +++++++--- 16 files changed, 346 insertions(+), 115 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .gitlab-ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..057d201 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,46 @@ +name: Test suite + +on: push + +jobs: + phpunit: + name: PHPUnit + runs-on: ubuntu-latest + strategy: + matrix: + php: ["7.1", "7.2", "7.3", "7.4"] + services: + mysql: + image: mysql:5.7 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: destructr_test + ports: + - 3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + mariadb: + image: mariadb:10.2 + env: + MARIADB_ROOT_PASSWORD: root + MARIADB_DATABASE: destructr_test + ports: + - 3306 + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Composer install + run: composer install -o --no-progress --ignore-platform-reqs + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql + coverage: none + ini-values: variables_order=EGPCS + - name: PHPUnit + env: + TEST_MYSQL_SERVER: 127.0.0.1 + TEST_MYSQL_PORT: ${{ job.services.mysql.ports['3306'] }} + TEST_MARIADB_SERVER: 127.0.0.1 + TEST_MARIADB_PORT: ${{ job.services.mariadb.ports['3306'] }} + run: ./vendor/bin/phpunit diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index fe71027..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,28 +0,0 @@ -image: php:7.1-alpine - -services: - - mysql:5.7 - -variables: - MYSQL_DATABASE: destructr_test - MYSQL_ROOT_PASSWORD: badpassword - -before_script: - - apk update - - apk add git - - docker-php-ext-install pdo - - curl -sS https://getcomposer.org/installer | php - - php composer.phar install - -test:local: - script: - - php composer.phar test-local - -test:mysql: - script: - - docker-php-ext-install pdo_mysql - - php composer.phar test-mysql - -test:sqlite: - script: - - php composer.phar test-sqlite diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 83e5c4f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -language: php -services: - - mysql -php: - - 7.3 - - 7.4 -before_install: - - mysql -e 'CREATE DATABASE test' - - docker run -d -p 127.0.0.1:3307:3306 --name mysqld -e MYSQL_DATABASE=destructrtest -e MYSQL_USER=destructrtest -e MYSQL_PASSWORD=destructrtest -e MYSQL_ROOT_PASSWORD=verysecret mariadb:10.2 --innodb_log_file_size=256MB --innodb_buffer_pool_size=512MB --max_allowed_packet=16MB - - sleep 15 -install: - - composer install -script: composer test \ No newline at end of file diff --git a/README.md b/README.md index 9deaa20..3f083f5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Destructr -[![Build Status](https://travis-ci.org/jobyone/destructr.svg?branch=main)](https://travis-ci.org/jobyone/destructr) +[![PHPUnit Tests](https://github.com/jobyone/destructr/actions/workflows/test.yml/badge.svg)](https://github.com/jobyone/destructr/actions/workflows/test.yml) Destructr is a specialized ORM that allows a seamless mix of structured, relational data with unstructured JSON data. diff --git a/tests/Drivers/AbstractSQLDriverIntegrationTest.php b/tests/Drivers/AbstractSQLDriverIntegrationTest.php index 634d35e..6b4b706 100644 --- a/tests/Drivers/AbstractSQLDriverIntegrationTest.php +++ b/tests/Drivers/AbstractSQLDriverIntegrationTest.php @@ -12,6 +12,21 @@ abstract class AbstractSQLDriverIntegrationTest extends TestCase use TestCaseTrait; const TEST_TABLE = 'integrationtest'; + protected static function DRIVER_USERNAME() + { + return null; + } + + protected static function DRIVER_PASSWORD() + { + return null; + } + + protected static function DRIVER_OPTIONS() + { + return null; + } + public static function setUpBeforeClass() { $pdo = static::createPDO(); @@ -138,10 +153,10 @@ abstract class AbstractSQLDriverIntegrationTest extends TestCase { $class = static::DRIVER_CLASS; return new $class( - static::DRIVER_DSN, - static::DRIVER_USERNAME, - static::DRIVER_PASSWORD, - static::DRIVER_OPTIONS + static::DRIVER_DSN(), + static::DRIVER_USERNAME(), + static::DRIVER_PASSWORD(), + static::DRIVER_OPTIONS() ); } @@ -157,10 +172,10 @@ abstract class AbstractSQLDriverIntegrationTest extends TestCase protected static function createPDO() { return new \PDO( - static::DRIVER_DSN, - static::DRIVER_USERNAME, - static::DRIVER_PASSWORD, - static::DRIVER_OPTIONS + static::DRIVER_DSN(), + static::DRIVER_USERNAME(), + static::DRIVER_PASSWORD(), + static::DRIVER_OPTIONS() ); } diff --git a/tests/Drivers/AbstractSQLDriverSchemaChangeTest.php b/tests/Drivers/AbstractSQLDriverSchemaChangeTest.php index 558da4a..b1647d2 100644 --- a/tests/Drivers/AbstractSQLDriverSchemaChangeTest.php +++ b/tests/Drivers/AbstractSQLDriverSchemaChangeTest.php @@ -15,6 +15,21 @@ abstract class AbstractSQLDriverSchemaChangeTest extends TestCase use TestCaseTrait; const TEST_TABLE = 'schematest'; + protected static function DRIVER_USERNAME() + { + return null; + } + + protected static function DRIVER_PASSWORD() + { + return null; + } + + protected static function DRIVER_OPTIONS() + { + return null; + } + public function testSchemaChanges() { // set up using schema A @@ -103,20 +118,20 @@ abstract class AbstractSQLDriverSchemaChangeTest extends TestCase { $class = static::DRIVER_CLASS; return new $class( - static::DRIVER_DSN, - static::DRIVER_USERNAME, - static::DRIVER_PASSWORD, - static::DRIVER_OPTIONS + static::DRIVER_DSN(), + static::DRIVER_USERNAME(), + static::DRIVER_PASSWORD(), + static::DRIVER_OPTIONS() ); } protected static function createPDO() { return new \PDO( - static::DRIVER_DSN, - static::DRIVER_USERNAME, - static::DRIVER_PASSWORD, - static::DRIVER_OPTIONS + static::DRIVER_DSN(), + static::DRIVER_USERNAME(), + static::DRIVER_PASSWORD(), + static::DRIVER_OPTIONS() ); } diff --git a/tests/Drivers/AbstractSQLDriverTest.php b/tests/Drivers/AbstractSQLDriverTest.php index 2510b18..0add0e3 100644 --- a/tests/Drivers/AbstractSQLDriverTest.php +++ b/tests/Drivers/AbstractSQLDriverTest.php @@ -1,6 +1,8 @@