diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..561c623
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,50 @@
+name: "Continuous Integration"
+
+on:
+ pull_request:
+ push:
+ branches:
+ - master
+jobs:
+ test:
+ name: "Test"
+ runs-on: "ubuntu-latest"
+
+ strategy:
+ matrix:
+ php-version:
+ - "7.4"
+ - "8.0"
+ - "8.1"
+ - "8.2"
+ - "8.3"
+ dependencies:
+ - "lowest"
+ - "highest"
+
+ steps:
+ - name: "Checkout"
+ uses: "actions/checkout@v4"
+
+ - name: "Install PHP"
+ uses: "shivammathur/setup-php@v2"
+ with:
+ coverage: "xdebug"
+ php-version: "${{ matrix.php-version }}"
+ ini-values: "zend.assertions=1"
+
+ - uses: "ramsey/composer-install@v2"
+ with:
+ dependency-versions: "${{ matrix.dependencies }}"
+
+ - name: "Run PHPUnit"
+ run: "./tests/phpunit-mysql8.sh"
+
+ - name: Upload coverage results to Coveralls
+ # skip php-coversalls for lowest deps
+ # it fails on lowest depedencies
+ if: "${{ 'highest' == matrix.dependencies }}"
+ env:
+ COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: |
+ vendor/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v
diff --git a/.gitignore b/.gitignore
index 4209400..51ada22 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@ vendor/
build/
composer.lock
phpunit.xml
+.phpunit.result.cache
diff --git a/composer.json b/composer.json
index 6dc1a27..2a76283 100644
--- a/composer.json
+++ b/composer.json
@@ -8,13 +8,14 @@
}
],
"require": {
- "doctrine/dbal": "^2.8",
- "symfony/yaml": "^4.1 | ^5"
+ "php": "^7.4 || ^8.0",
+ "doctrine/dbal": "^3.0",
+ "symfony/yaml": "^4.1 | ^5 | ^6 | ^7"
},
"require-dev": {
- "phpunit/phpunit": "^7",
- "satooshi/php-coveralls": "^1.0.1",
- "thecodingmachine/dbal-fluid-schema-builder": "^1.3.0"
+ "phpunit/phpunit": "^9.6.16",
+ "php-coveralls/php-coveralls": "^2.7.0",
+ "thecodingmachine/dbal-fluid-schema-builder": "^2.0.1"
},
"autoload": {
"psr-4": {
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index d7271c6..2b38a26 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
- syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
@@ -18,7 +17,7 @@
-
+
@@ -26,16 +25,13 @@
-
-
+
+
src/
-
- src/Test
-
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/src/Command/ApplySchemaCommand.php b/src/Command/ApplySchemaCommand.php
index 0974bab..66afae5 100644
--- a/src/Command/ApplySchemaCommand.php
+++ b/src/Command/ApplySchemaCommand.php
@@ -12,7 +12,7 @@
*/
class ApplySchemaCommand extends AbstractSchemaCommand
{
- protected function configure()
+ protected function configure(): void
{
$this
->setName('schema:apply')
@@ -23,13 +23,14 @@ protected function configure()
;
}
- protected function execute(InputInterface $input, OutputInterface $output)
+ protected function execute(InputInterface $input, OutputInterface $output): int
{
if ($input->getOption('dry-run')) {
$this->getMigrationSql($input, $output);
} else {
$this->updateSchema($input, $output);
}
+ return 0;
}
protected function updateSchema(InputInterface $input, OutputInterface $output)
diff --git a/src/Command/DumpSchemaCommand.php b/src/Command/DumpSchemaCommand.php
index 77dd9c3..2d075ba 100644
--- a/src/Command/DumpSchemaCommand.php
+++ b/src/Command/DumpSchemaCommand.php
@@ -12,7 +12,7 @@
*/
class DumpSchemaCommand extends AbstractSchemaCommand
{
- protected function configure()
+ protected function configure(): void
{
$this
->setName('schema:dump')
@@ -20,8 +20,9 @@ protected function configure()
;
}
- protected function execute(InputInterface $input, OutputInterface $output)
+ protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->schemaVersionControlService->dumpSchema();
+ return 0;
}
}
diff --git a/src/Command/SchemaStatusCommand.php b/src/Command/SchemaStatusCommand.php
index 0fc6cda..1f7cbca 100644
--- a/src/Command/SchemaStatusCommand.php
+++ b/src/Command/SchemaStatusCommand.php
@@ -13,7 +13,7 @@
*/
class SchemaStatusCommand extends AbstractSchemaCommand
{
- protected function configure()
+ protected function configure(): void
{
$this
->setName('schema:status')
@@ -21,7 +21,7 @@ protected function configure()
;
}
- protected function execute(InputInterface $input, OutputInterface $output)
+ protected function execute(InputInterface $input, OutputInterface $output): int
{
$diff = $this->schemaVersionControlService->getSchemaDiff(true);
@@ -29,7 +29,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
&& empty($diff->newTables)
&& empty($diff->removedTables)){
$output->writeln('Schema up-to-date.');
- return;
+ return 0;
}
foreach ($diff->changedTables as $changedTable) {
@@ -53,6 +53,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('- Command `schema:dump` to save local changes into schema file.');
$output->writeln('- Command `schema:apply` to migrate database version/discard local changes.');
$output->writeln('- Manual migration (you can start from a SQL script obtained by using command `schema:apply --dry-run`.');
+ return 0;
}
protected function tableDiffStatus(TableDiff $tableDiff, InputInterface $input, OutputInterface $output)
diff --git a/tests/AbstractSchemaTest.php b/tests/AbstractSchemaTest.php
index 743a19b..740bd6a 100644
--- a/tests/AbstractSchemaTest.php
+++ b/tests/AbstractSchemaTest.php
@@ -13,7 +13,7 @@ abstract class AbstractSchemaTest extends TestCase
/** @var Connection */
protected static $dbConnection;
- public static function setUpBeforeClass()
+ public static function setUpBeforeClass(): void
{
self::resetConnection();
$dbConnection = self::getConnection();
diff --git a/tests/SchemaVersionControlServiceTest.php b/tests/SchemaVersionControlServiceTest.php
index 66cfcc0..ec4b90b 100644
--- a/tests/SchemaVersionControlServiceTest.php
+++ b/tests/SchemaVersionControlServiceTest.php
@@ -17,12 +17,12 @@ public function testLoad()
$tables = $schema->getTables();
$this->assertEquals(2, count($tables));
$animalTable = $schema->getTable('animal');
- $this->assertEquals(['id'], $animalTable->getPrimaryKeyColumns());
+ $this->assertEquals(['id'], $animalTable->getPrimaryKey()->getColumns());
}
public function testIndexes()
{
- $schemaVersionControlService = new SchemaVersionControlService(self::$dbConnection, __DIR__.'/var/schema2.yml');
+ $schemaVersionControlService = new SchemaVersionControlService(self::$dbConnection, __DIR__.'/etc/schema2.yml');
$schema = $schemaVersionControlService->loadSchemaFile();
$userTable = $schema->getTable('users');
@@ -32,7 +32,7 @@ public function testIndexes()
public function testComment()
{
- $schemaVersionControlService = new SchemaVersionControlService(self::$dbConnection, __DIR__.'/var/schema2.yml');
+ $schemaVersionControlService = new SchemaVersionControlService(self::$dbConnection, __DIR__.'/etc/schema2.yml');
$schema = $schemaVersionControlService->loadSchemaFile();
$animalTable = $schema->getTable('animal');
diff --git a/tests/etc/schema2.yml b/tests/etc/schema2.yml
new file mode 100644
index 0000000..75502a1
--- /dev/null
+++ b/tests/etc/schema2.yml
@@ -0,0 +1,178 @@
+schema:
+ tables:
+ animal:
+ comment: 'test comment'
+ columns:
+ id:
+ primary_key: true
+ type: integer
+ not_null: true
+ auto_increment: true
+ comment: '@Autoincrement'
+ name:
+ type: string
+ length: 45
+ not_null: true
+ order: integer
+ indexes:
+ IDX_6AAB231FAB06D34C:
+ column: name
+ lengths:
+ - null
+ cat:
+ columns:
+ id:
+ primary_key: true
+ type: integer
+ not_null: true
+ cuteness_level: integer
+ foreign_keys:
+ FK_9E5E43A81147174B:
+ column: id
+ references:
+ table: animal
+ column: id
+ onDelete: null
+ onUpdate: null
+ users:
+ columns:
+ id:
+ primary_key: true
+ type: integer
+ not_null: true
+ country_id:
+ type: integer
+ not_null: true
+ login:
+ type: string
+ length: 255
+ not_null: true
+ password:
+ type: string
+ length: 255
+ status:
+ type: string
+ length: 10
+ indexes:
+ users_login_idx:
+ column: login
+ unique: true
+ lengths:
+ - null
+ IDX_1483A5E9F74CCB5C:
+ column: country_id
+ lengths:
+ - null
+ users_status_country_idx:
+ columns:
+ - status
+ - country_id
+ lengths:
+ - null
+ - null
+ foreign_keys:
+ FK_1483A5E91147174B:
+ column: id
+ references:
+ table: contact
+ column: id
+ onDelete: null
+ onUpdate: null
+ FK_1483A5E9F74CCB5C:
+ column: country_id
+ references:
+ table: country
+ column: id
+ onDelete: null
+ onUpdate: null
+ contact:
+ columns:
+ id:
+ primary_key: true
+ type: integer
+ not_null: true
+ manager_id: integer
+ email:
+ type: string
+ length: 255
+ not_null: true
+ indexes:
+ IDX_4C62E63873739B88:
+ column: manager_id
+ lengths:
+ - null
+ foreign_keys:
+ FK_4C62E6381147174B:
+ column: id
+ references:
+ table: person
+ column: id
+ onDelete: null
+ onUpdate: null
+ FK_4C62E63873739B88:
+ column: manager_id
+ references:
+ table: contact
+ column: id
+ onDelete: null
+ onUpdate: null
+ person:
+ columns:
+ id:
+ primary_key: true
+ type: integer
+ not_null: true
+ auto_increment: true
+ comment: '@Autoincrement'
+ name:
+ type: string
+ length: 255
+ not_null: true
+ modified_at:
+ type: datetime
+ length: 0
+ order: integer
+ country:
+ columns:
+ id:
+ primary_key: true
+ type: integer
+ not_null: true
+ auto_increment: true
+ comment: '@Autoincrement'
+ label:
+ type: string
+ length: 255
+ not_null: true
+ dog:
+ columns:
+ id:
+ primary_key: true
+ type: integer
+ not_null: true
+ owner_id:
+ type: integer
+ not_null: true
+ race:
+ type: string
+ length: 45
+ indexes:
+ IDX_812C397D8FCB80A4:
+ column: owner_id
+ lengths:
+ - null
+ foreign_keys:
+ FK_812C397D1147174B:
+ column: id
+ references:
+ table: animal
+ column: id
+ onDelete: null
+ onUpdate: null
+ FK_812C397D8FCB80A4:
+ column: owner_id
+ references:
+ table: person
+ column: id
+ onDelete: null
+ onUpdate: null
diff --git a/tests/phpunit-mysql8.sh b/tests/phpunit-mysql8.sh
new file mode 100755
index 0000000..513909d
--- /dev/null
+++ b/tests/phpunit-mysql8.sh
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+
+# Use this file to start a MySQL8 database using Docker and then run the test suite on the MySQL8 database.
+
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+cd "$DIR" || exit
+cd ..
+
+docker run --rm --name schema_manager_test_case -p 3306:3306 -p 33060:33060 -e MYSQL_ROOT_PASSWORD=password -d mysql:8 mysqld --default-authentication-plugin=mysql_native_password
+
+# Let's wait for MySQL 8 to start
+sleep 20
+
+vendor/bin/phpunit -c phpunit.xml.dist "$NO_COVERAGE"
+RESULT_CODE=$?
+
+docker stop schema_manager_test_case
+
+exit $RESULT_CODE