diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index f60953a940..5824172315 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -1,4 +1,3 @@ - name: "Continuous Integration" on: @@ -18,6 +17,18 @@ jobs: with: args: --from=${{ github.event.pull_request.base.sha }} + composer_normalize: + name: "Composer Normalize" + runs-on: "ubuntu-20.04" + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - uses: "docker://ergebnis/composer-normalize-action:latest" + with: + args: "--dry-run" + phpunit: name: "PHPUnit" runs-on: "ubuntu-20.04" diff --git a/composer.json b/composer.json index d2790b1651..17b30da7ee 100644 --- a/composer.json +++ b/composer.json @@ -2,43 +2,69 @@ "name": "doctrine/migrations", "type": "library", "description": "PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easily deploying changes to it. It is a very easy to use and a powerful tool.", - "keywords": ["php", "database", "migrations", "dbal"], + "keywords": [ + "database", + "migrations", + "dbal" + ], "homepage": "https://www.doctrine-project.org/projects/migrations.html", "license": "MIT", "authors": [ - {"name": "Benjamin Eberlei", "email": "kontakt@beberlei.de"}, - {"name": "Jonathan Wage", "email": "jonwage@gmail.com"}, - {"name": "Michael Simonson", "email": "contact@mikesimonson.com" } + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Michael Simonson", + "email": "contact@mikesimonson.com" + } ], "require": { "php": "^7.2", + "composer/package-versions-deprecated": "^1.8", "doctrine/dbal": "^2.10", "doctrine/event-manager": "^1.0", - "composer/package-versions-deprecated": "^1.8", "ocramius/proxy-manager": "^2.0.2", "psr/log": "^1.1.3", - "symfony/console": "^3.4||^4.4.16||^5.0", - "symfony/stopwatch": "^3.4||^4.0||^5.0" + "symfony/console": "^3.4 || ^4.4.16 || ^5.0", + "symfony/stopwatch": "^3.4 || ^4.0 || ^5.0" }, "require-dev": { "ext-pdo_sqlite": "*", "doctrine/coding-standard": "^8.0", "doctrine/orm": "^2.6", - "doctrine/persistence": "^1.3||^2.0", + "doctrine/persistence": "^1.3 || ^2.0", "doctrine/sql-formatter": "^1.0", + "ergebnis/composer-normalize": "^2.11", "phpstan/phpstan": "^0.12", "phpstan/phpstan-deprecation-rules": "^0.12", "phpstan/phpstan-phpunit": "^0.12", "phpstan/phpstan-strict-rules": "^0.12", "phpstan/phpstan-symfony": "^0.12", "phpunit/phpunit": "^8.5 || ^9.4", - "symfony/process": "^3.4||^4.0||^5.0", - "symfony/yaml": "^3.4||^4.0||^5.0" + "symfony/process": "^3.4 || ^4.0 || ^5.0", + "symfony/yaml": "^3.4 || ^4.0 || ^5.0" }, "suggest": { "doctrine/sql-formatter": "Allows to generate formatted SQL with the diff command.", "symfony/yaml": "Allows the use of yaml for migration configuration files." }, + "config": { + "sort-packages": true + }, + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + }, + "composer-normalize": { + "indent-size": 4, + "indent-style": "space" + } + }, "autoload": { "psr-4": { "Doctrine\\Migrations\\": "lib/Doctrine/Migrations" @@ -49,17 +75,6 @@ "Doctrine\\Migrations\\Tests\\": "tests/Doctrine/Migrations/Tests" } }, - "config": { - "sort-packages": true, - "platform": { - "php": "7.2.2" - } - }, - "extra": { - "branch-alias": { - "dev-master": "3.0.x-dev" - } - }, "bin": [ "bin/doctrine-migrations" ] diff --git a/download-box.sh b/download-box.sh index 209275c17d..36f31d00e5 100755 --- a/download-box.sh +++ b/download-box.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash if [ ! -f box.phar ]; then - wget https://github.com/box-project/box/releases/download/3.9.0/box.phar -O box.phar + wget https://github.com/box-project/box/releases/download/3.9.1/box.phar -O box.phar fi diff --git a/lib/Doctrine/Migrations/Configuration/Configuration.php b/lib/Doctrine/Migrations/Configuration/Configuration.php index a860fcbf4b..d3e0ab3f54 100644 --- a/lib/Doctrine/Migrations/Configuration/Configuration.php +++ b/lib/Doctrine/Migrations/Configuration/Configuration.php @@ -9,13 +9,14 @@ use Doctrine\Migrations\Exception\MigrationException; use Doctrine\Migrations\Metadata\Storage\MetadataStorageConfiguration; -use function strcasecmp; +use function strtolower; /** * The Configuration class is responsible for defining migration configuration information. */ final class Configuration { + public const VERSIONS_ORGANIZATION_NONE = 'none'; public const VERSIONS_ORGANIZATION_BY_YEAR = 'year'; public const VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH = 'year_and_month'; @@ -177,12 +178,19 @@ public function isDatabasePlatformChecked(): bool public function setMigrationOrganization(string $migrationOrganization): void { $this->assertNotFrozen(); - if (strcasecmp($migrationOrganization, self::VERSIONS_ORGANIZATION_BY_YEAR) === 0) { - $this->setMigrationsAreOrganizedByYear(); - } elseif (strcasecmp($migrationOrganization, self::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH) === 0) { - $this->setMigrationsAreOrganizedByYearAndMonth(); - } else { - throw UnknownConfigurationValue::new('organize_migrations', $migrationOrganization); + + switch (strtolower($migrationOrganization)) { + case self::VERSIONS_ORGANIZATION_NONE: + $this->setMigrationsAreOrganizedByYearAndMonth(false); + break; + case self::VERSIONS_ORGANIZATION_BY_YEAR: + $this->setMigrationsAreOrganizedByYear(); + break; + case self::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH: + $this->setMigrationsAreOrganizedByYearAndMonth(); + break; + default: + throw UnknownConfigurationValue::new('organize_migrations', $migrationOrganization); } } } diff --git a/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php b/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php index db6b8a24e0..e1f8156e52 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php @@ -80,4 +80,17 @@ public function testMigrationOrganizationWithWrongValue(): void $config = new Configuration(); $config->setMigrationOrganization('foo'); } + + public function testMigrationOrganizationCanBeReset(): void + { + $config = new Configuration(); + + $config->setMigrationOrganization(Configuration::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH); + self::assertTrue($config->areMigrationsOrganizedByYearAndMonth()); + self::assertTrue($config->areMigrationsOrganizedByYear()); + + $config->setMigrationOrganization(Configuration::VERSIONS_ORGANIZATION_NONE); + self::assertFalse($config->areMigrationsOrganizedByYearAndMonth()); + self::assertFalse($config->areMigrationsOrganizedByYear()); + } } diff --git a/tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php b/tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php index e6f0ca26f5..1da13899a2 100644 --- a/tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php +++ b/tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php @@ -7,12 +7,19 @@ use Doctrine\Migrations\Generator\ClassNameGenerator; use PHPUnit\Framework\TestCase; +use function method_exists; + class ClassNameGeneratorTest extends TestCase { public function testName(): void { $generator = new ClassNameGenerator(); $fqcn = $generator->generateClassName('Foo'); - self::assertRegExp('/^Foo\\\\Version[0-9]{14}$/', $fqcn); + + if (method_exists($this, 'assertMatchesRegularExpression')) { + $this->assertMatchesRegularExpression('/^Foo\\\\Version[0-9]{14}$/', $fqcn); + } else { + self::assertRegExp('/^Foo\\\\Version[0-9]{14}$/', $fqcn); + } } } diff --git a/tests/Doctrine/Migrations/Tests/Generator/DiffGeneratorTest.php b/tests/Doctrine/Migrations/Tests/Generator/DiffGeneratorTest.php index e4e4a05908..f485e608c2 100644 --- a/tests/Doctrine/Migrations/Tests/Generator/DiffGeneratorTest.php +++ b/tests/Doctrine/Migrations/Tests/Generator/DiffGeneratorTest.php @@ -88,13 +88,9 @@ static function ($name): bool { ->method('createSchema') ->willReturn($toSchema); - $toSchema->expects(self::at(1)) + $toSchema->expects(self::exactly(2)) ->method('dropTable') - ->with('schema.table_name2'); - - $toSchema->expects(self::at(2)) - ->method('dropTable') - ->with('schema.table_name3'); + ->will(self::onConsecutiveCalls('schema.table_name2', 'schema.table_name3')); $fromSchema->expects(self::once()) ->method('getMigrateToSql') @@ -106,15 +102,13 @@ static function ($name): bool { ->with($toSchema, $this->platform) ->willReturn(['UPDATE table SET value = 1']); - $this->migrationSqlGenerator->expects(self::at(0)) - ->method('generate') - ->with(['UPDATE table SET value = 2'], true, 80) - ->willReturn('test1'); - - $this->migrationSqlGenerator->expects(self::at(1)) + $this->migrationSqlGenerator->expects(self::exactly(2)) ->method('generate') - ->with(['UPDATE table SET value = 1'], true, 80) - ->willReturn('test2'); + ->with(self::logicalOr( + self::equalTo(['UPDATE table SET value = 2']), + self::equalTo(['UPDATE table SET value = 1']) + ), true, 80) + ->will(self::onConsecutiveCalls('test1', 'test2')); $this->migrationGenerator->expects(self::once()) ->method('generateMigration') @@ -163,15 +157,13 @@ public function testGenerateFromEmptySchema(): void ->with($toSchema, $this->platform) ->willReturn(['DROP TABLE table_name']); - $this->migrationSqlGenerator->expects(self::at(0)) - ->method('generate') - ->with(['CREATE TABLE table_name'], false, 120, true) - ->willReturn('test up'); - - $this->migrationSqlGenerator->expects(self::at(1)) + $this->migrationSqlGenerator->expects(self::exactly(2)) ->method('generate') - ->with(['DROP TABLE table_name'], false, 120, true) - ->willReturn('test down'); + ->with(self::logicalOr( + self::equalTo(['CREATE TABLE table_name']), + self::equalTo(['DROP TABLE table_name']) + ), false, 120, true) + ->will(self::onConsecutiveCalls('test up', 'test down')); $this->migrationGenerator->expects(self::once()) ->method('generateMigration') diff --git a/tests/Doctrine/Migrations/Tests/RollupTest.php b/tests/Doctrine/Migrations/Tests/RollupTest.php index 1846f22d74..6f30c1cc1c 100644 --- a/tests/Doctrine/Migrations/Tests/RollupTest.php +++ b/tests/Doctrine/Migrations/Tests/RollupTest.php @@ -50,9 +50,12 @@ public function testRollup(): void ->willReturn(new AvailableMigrationsSet([$m1])); $this->storage - ->expects(self::at(0))->method('reset')->with(); + ->expects(self::exactly(1)) + ->method('reset') + ->with(); + $this->storage - ->expects(self::at(1)) + ->expects(self::exactly(1)) ->method('complete') ->willReturnCallback(static function (ExecutionResult $result): void { self::assertEquals(new Version('A'), $result->getVersion()); diff --git a/tests/Doctrine/Migrations/Tests/SchemaDumperTest.php b/tests/Doctrine/Migrations/Tests/SchemaDumperTest.php index 61c4dc88d6..c87e2d6a98 100644 --- a/tests/Doctrine/Migrations/Tests/SchemaDumperTest.php +++ b/tests/Doctrine/Migrations/Tests/SchemaDumperTest.php @@ -76,15 +76,13 @@ public function testDump(): void ->method('getDropTableSQL') ->willReturn('DROP TABLE test'); - $this->migrationSqlGenerator->expects(self::at(0)) + $this->migrationSqlGenerator->expects(self::exactly(2)) ->method('generate') - ->with(['CREATE TABLE test']) - ->willReturn('up'); - - $this->migrationSqlGenerator->expects(self::at(1)) - ->method('generate') - ->with(['DROP TABLE test']) - ->willReturn('down'); + ->with(self::logicalOr( + self::equalTo(['CREATE TABLE test']), + self::equalTo(['DROP TABLE test']) + )) + ->will(self::onConsecutiveCalls('up', 'down')); $this->migrationGenerator->expects(self::once()) ->method('generateMigration') diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php index 350c9dce2d..8d535325a2 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php @@ -5,6 +5,7 @@ namespace Doctrine\Migrations\Tests\Tools\Console\Command; use DateTimeImmutable; +use Doctrine\DBAL\Version as DBALVersion; use Doctrine\Migrations\Configuration\Configuration; use Doctrine\Migrations\Configuration\Connection\ExistingConnection; use Doctrine\Migrations\Configuration\Migration\ExistingConfiguration; @@ -73,6 +74,13 @@ public function testExecute(): void $lines = array_map('trim', explode("\n", trim($this->commandTester->getDisplay(true)))); + if (DBALVersion::compare('2.11.0') > 0) { + // Trailing space is necessary to pad size to match `...\PDO\SQLite\Driver` namespace length + $databaseDriver = 'Doctrine\DBAL\Driver\PDOSqlite\Driver '; + } else { + $databaseDriver = 'Doctrine\DBAL\Driver\PDO\SQLite\Driver'; + } + self::assertSame( [ '+----------------------+----------------------+------------------------------------------------------------------------+', @@ -82,7 +90,7 @@ public function testExecute(): void '| | Table Name | doctrine_migration_versions |', '| | Column Name | version |', '|----------------------------------------------------------------------------------------------------------------------|', - '| Database | Driver | Doctrine\DBAL\Driver\PDOSqlite\Driver |', + '| Database | Driver | ' . $databaseDriver . ' |', '| | Name | |', '|----------------------------------------------------------------------------------------------------------------------|', '| Versions | Previous | 1230 |',