From 7daab71a65b466552351be468709bd897ed4b4a7 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Mon, 23 Nov 2020 18:36:08 -0700 Subject: [PATCH 01/14] Updated box to 3.9.1 --- download-box.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 4f6bea5f9fa163fd5a0fae0555ee6a1be16b12e1 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Mon, 23 Nov 2020 19:22:03 -0700 Subject: [PATCH 02/14] Allow for PDO namespaces pre and post dbal 2.11 --- .../Tests/Tools/Console/Command/StatusCommandTest.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php index 350c9dce2d..c5657ed7a4 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,12 @@ public function testExecute(): void $lines = array_map('trim', explode("\n", trim($this->commandTester->getDisplay(true)))); + if (DBALVersion::compare('2.11.0') > 0) { + $databaseDriver = 'Doctrine\DBAL\Driver\PDOSqlite\Driver '; // Trailing space bufferes outout assertion + } else { + $databaseDriver = 'Doctrine\DBAL\Driver\PDO\SQLite\Driver'; + } + self::assertSame( [ '+----------------------+----------------------+------------------------------------------------------------------------+', @@ -82,7 +89,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 |', From d4a5fdf376df2818873fec1ea4d5c4fe167edbc7 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Tue, 24 Nov 2020 01:44:14 -0700 Subject: [PATCH 03/14] Reformatted composer.json and removed config platform of 7.2 --- composer.json | 134 +++++++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 62 deletions(-) diff --git a/composer.json b/composer.json index d2790b1651..c79f21bea3 100644 --- a/composer.json +++ b/composer.json @@ -1,66 +1,76 @@ { - "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"], - "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" } - ], - "require": { - "php": "^7.2", - "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" + "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": [ + "database", + "migrations", + "dbal" + ], + "homepage": "https://www.doctrine-project.org/projects/migrations.html", + "license": "MIT", + "authors": [ + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" }, - "require-dev": { - "ext-pdo_sqlite": "*", - "doctrine/coding-standard": "^8.0", - "doctrine/orm": "^2.6", - "doctrine/persistence": "^1.3||^2.0", - "doctrine/sql-formatter": "^1.0", - "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" + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" }, - "suggest": { - "doctrine/sql-formatter": "Allows to generate formatted SQL with the diff command.", - "symfony/yaml": "Allows the use of yaml for migration configuration files." - }, - "autoload": { - "psr-4": { - "Doctrine\\Migrations\\": "lib/Doctrine/Migrations" - } - }, - "autoload-dev": { - "psr-4": { - "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" - ] + { + "name": "Michael Simonson", + "email": "contact@mikesimonson.com" + } + ], + "require": { + "php": "^7.2", + "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" + }, + "require-dev": { + "ext-pdo_sqlite": "*", + "doctrine/coding-standard": "^8.0", + "doctrine/orm": "^2.6", + "doctrine/persistence": "^1.3||^2.0", + "doctrine/sql-formatter": "^1.0", + "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" + }, + "suggest": { + "doctrine/sql-formatter": "Allows to generate formatted SQL with the diff command.", + "symfony/yaml": "Allows the use of yaml for migration configuration files." + }, + "autoload": { + "psr-4": { + "Doctrine\\Migrations\\": "lib/Doctrine/Migrations" + } + }, + "autoload-dev": { + "psr-4": { + "Doctrine\\Migrations\\Tests\\": "tests/Doctrine/Migrations/Tests" + } + }, + "config": { + "sort-packages": true + }, + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "bin": [ + "bin/doctrine-migrations" + ] } From ad08c6ab948b1e931b148d8b33b612a59ae17c50 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Tue, 24 Nov 2020 02:05:29 -0700 Subject: [PATCH 04/14] Fixed at() calls in tests --- .../Generator/ClassNameGeneratorTest.php | 2 +- .../Tests/Generator/DiffGeneratorTest.php | 36 ++++++++----------- .../Doctrine/Migrations/Tests/RollupTest.php | 7 ++-- .../Migrations/Tests/SchemaDumperTest.php | 14 ++++---- 4 files changed, 26 insertions(+), 33 deletions(-) diff --git a/tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php b/tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php index e6f0ca26f5..74de91464f 100644 --- a/tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php +++ b/tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php @@ -13,6 +13,6 @@ public function testName(): void { $generator = new ClassNameGenerator(); $fqcn = $generator->generateClassName('Foo'); - self::assertRegExp('/^Foo\\\\Version[0-9]{14}$/', $fqcn); + $this->assertMatchesRegularExpression('/^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..0b4bf3d4bc 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($this->exactly(2)) ->method('dropTable') - ->with('schema.table_name2'); - - $toSchema->expects(self::at(2)) - ->method('dropTable') - ->with('schema.table_name3'); + ->will($this->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($this->exactly(2)) ->method('generate') - ->with(['UPDATE table SET value = 1'], true, 80) - ->willReturn('test2'); + ->with($this->logicalOr( + $this->equalTo(['UPDATE table SET value = 2']), + $this->equalTo(['UPDATE table SET value = 1']) + ), true, 80) + ->will($this->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($this->exactly(2)) ->method('generate') - ->with(['DROP TABLE table_name'], false, 120, true) - ->willReturn('test down'); + ->with($this->logicalOr( + $this->equalTo(['CREATE TABLE table_name']), + $this->equalTo(['DROP TABLE table_name']) + ), false, 120, true) + ->will($this->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..47f56f1f65 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($this->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($this->logicalOr( + $this->equalTo(['CREATE TABLE test']), + $this->equalTo(['DROP TABLE test']) + )) + ->will($this->onConsecutiveCalls('up', 'down')); $this->migrationGenerator->expects(self::once()) ->method('generateMigration') From 9fab9607937ccbc42d6e0e5e2c737412989ea2e6 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Tue, 24 Nov 2020 02:17:40 -0700 Subject: [PATCH 05/14] Added typehint to setMigrationOrganization for string or bool; fixed function defs in tests --- .../Configuration/Configuration.php | 17 +++++++++++- .../Tests/Configuration/ConfigurationTest.php | 26 +++++++++++++++++++ .../Tests/Generator/DiffGeneratorTest.php | 12 ++++----- .../Migrations/Tests/SchemaDumperTest.php | 6 ++--- 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/Migrations/Configuration/Configuration.php b/lib/Doctrine/Migrations/Configuration/Configuration.php index a860fcbf4b..a210289d17 100644 --- a/lib/Doctrine/Migrations/Configuration/Configuration.php +++ b/lib/Doctrine/Migrations/Configuration/Configuration.php @@ -9,6 +9,7 @@ use Doctrine\Migrations\Exception\MigrationException; use Doctrine\Migrations\Metadata\Storage\MetadataStorageConfiguration; +use function is_string; use function strcasecmp; /** @@ -174,9 +175,23 @@ public function isDatabasePlatformChecked(): bool return $this->checkDbPlatform; } - public function setMigrationOrganization(string $migrationOrganization): void + /** + * @param string | bool $migrationOrganization + */ + public function setMigrationOrganization($migrationOrganization): void { $this->assertNotFrozen(); + + if ($migrationOrganization === false) { + $this->setMigrationsAreOrganizedByYearAndMonth(false); + + return; + } + + if (! is_string($migrationOrganization)) { + throw UnknownConfigurationValue::new('organize_migrations', $migrationOrganization); + } + if (strcasecmp($migrationOrganization, self::VERSIONS_ORGANIZATION_BY_YEAR) === 0) { $this->setMigrationsAreOrganizedByYear(); } elseif (strcasecmp($migrationOrganization, self::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH) === 0) { diff --git a/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php b/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php index db6b8a24e0..55bc78c92e 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php @@ -80,4 +80,30 @@ public function testMigrationOrganizationWithWrongValue(): void $config = new Configuration(); $config->setMigrationOrganization('foo'); } + + public function testMigrationOrganizationCanBeResetToFalse(): void + { + $config = new Configuration(); + $config->setMigrationOrganization(Configuration::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH); + $config->setMigrationOrganization(false); + + self::assertFalse($config->areMigrationsOrganizedByYearAndMonth()); + self::assertFalse($config->areMigrationsOrganizedByYear()); + } + + public function testMigrationOrganizationMustBeSetToFalseOrStringTestTrue(): void + { + $this->expectException(UnknownConfigurationValue::class); + $config = new Configuration(); + $config->setMigrationOrganization(Configuration::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH); + $config->setMigrationOrganization(true); + } + + public function testMigrationOrganizationMustBeSetToFalseOrStringTestNumber(): void + { + $this->expectException(UnknownConfigurationValue::class); + $config = new Configuration(); + $config->setMigrationOrganization(Configuration::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH); + $config->setMigrationOrganization(123); + } } diff --git a/tests/Doctrine/Migrations/Tests/Generator/DiffGeneratorTest.php b/tests/Doctrine/Migrations/Tests/Generator/DiffGeneratorTest.php index 0b4bf3d4bc..657858d5ac 100644 --- a/tests/Doctrine/Migrations/Tests/Generator/DiffGeneratorTest.php +++ b/tests/Doctrine/Migrations/Tests/Generator/DiffGeneratorTest.php @@ -105,9 +105,9 @@ static function ($name): bool { $this->migrationSqlGenerator->expects($this->exactly(2)) ->method('generate') ->with($this->logicalOr( - $this->equalTo(['UPDATE table SET value = 2']), - $this->equalTo(['UPDATE table SET value = 1']) - ), true, 80) + $this->equalTo(['UPDATE table SET value = 2']), + $this->equalTo(['UPDATE table SET value = 1']) + ), true, 80) ->will($this->onConsecutiveCalls('test1', 'test2')); $this->migrationGenerator->expects(self::once()) @@ -160,9 +160,9 @@ public function testGenerateFromEmptySchema(): void $this->migrationSqlGenerator->expects($this->exactly(2)) ->method('generate') ->with($this->logicalOr( - $this->equalTo(['CREATE TABLE table_name']), - $this->equalTo(['DROP TABLE table_name']) - ), false, 120, true) + $this->equalTo(['CREATE TABLE table_name']), + $this->equalTo(['DROP TABLE table_name']) + ), false, 120, true) ->will($this->onConsecutiveCalls('test up', 'test down')); $this->migrationGenerator->expects(self::once()) diff --git a/tests/Doctrine/Migrations/Tests/SchemaDumperTest.php b/tests/Doctrine/Migrations/Tests/SchemaDumperTest.php index 47f56f1f65..24ab9aaea6 100644 --- a/tests/Doctrine/Migrations/Tests/SchemaDumperTest.php +++ b/tests/Doctrine/Migrations/Tests/SchemaDumperTest.php @@ -79,9 +79,9 @@ public function testDump(): void $this->migrationSqlGenerator->expects($this->exactly(2)) ->method('generate') ->with($this->logicalOr( - $this->equalTo(['CREATE TABLE test']), - $this->equalTo(['DROP TABLE test']) - )) + $this->equalTo(['CREATE TABLE test']), + $this->equalTo(['DROP TABLE test']) + )) ->will($this->onConsecutiveCalls('up', 'down')); $this->migrationGenerator->expects(self::once()) From 8af8409932623ec93f97306f23a7ebd5b92d4f3f Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Tue, 24 Nov 2020 02:29:29 -0700 Subject: [PATCH 06/14] phpstan fixes; change class calls to static --- .../Tests/Configuration/ConfigurationTest.php | 8 ------- .../Generator/ClassNameGeneratorTest.php | 7 +++++- .../Tests/Generator/DiffGeneratorTest.php | 24 +++++++++---------- .../Migrations/Tests/SchemaDumperTest.php | 10 ++++---- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php b/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php index 55bc78c92e..b8fbb59c33 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php @@ -98,12 +98,4 @@ public function testMigrationOrganizationMustBeSetToFalseOrStringTestTrue(): voi $config->setMigrationOrganization(Configuration::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH); $config->setMigrationOrganization(true); } - - public function testMigrationOrganizationMustBeSetToFalseOrStringTestNumber(): void - { - $this->expectException(UnknownConfigurationValue::class); - $config = new Configuration(); - $config->setMigrationOrganization(Configuration::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH); - $config->setMigrationOrganization(123); - } } diff --git a/tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php b/tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php index 74de91464f..03f61f3e4c 100644 --- a/tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php +++ b/tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php @@ -13,6 +13,11 @@ public function testName(): void { $generator = new ClassNameGenerator(); $fqcn = $generator->generateClassName('Foo'); - $this->assertMatchesRegularExpression('/^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 657858d5ac..f485e608c2 100644 --- a/tests/Doctrine/Migrations/Tests/Generator/DiffGeneratorTest.php +++ b/tests/Doctrine/Migrations/Tests/Generator/DiffGeneratorTest.php @@ -88,9 +88,9 @@ static function ($name): bool { ->method('createSchema') ->willReturn($toSchema); - $toSchema->expects($this->exactly(2)) + $toSchema->expects(self::exactly(2)) ->method('dropTable') - ->will($this->onConsecutiveCalls('schema.table_name2', 'schema.table_name3')); + ->will(self::onConsecutiveCalls('schema.table_name2', 'schema.table_name3')); $fromSchema->expects(self::once()) ->method('getMigrateToSql') @@ -102,13 +102,13 @@ static function ($name): bool { ->with($toSchema, $this->platform) ->willReturn(['UPDATE table SET value = 1']); - $this->migrationSqlGenerator->expects($this->exactly(2)) + $this->migrationSqlGenerator->expects(self::exactly(2)) ->method('generate') - ->with($this->logicalOr( - $this->equalTo(['UPDATE table SET value = 2']), - $this->equalTo(['UPDATE table SET value = 1']) + ->with(self::logicalOr( + self::equalTo(['UPDATE table SET value = 2']), + self::equalTo(['UPDATE table SET value = 1']) ), true, 80) - ->will($this->onConsecutiveCalls('test1', 'test2')); + ->will(self::onConsecutiveCalls('test1', 'test2')); $this->migrationGenerator->expects(self::once()) ->method('generateMigration') @@ -157,13 +157,13 @@ public function testGenerateFromEmptySchema(): void ->with($toSchema, $this->platform) ->willReturn(['DROP TABLE table_name']); - $this->migrationSqlGenerator->expects($this->exactly(2)) + $this->migrationSqlGenerator->expects(self::exactly(2)) ->method('generate') - ->with($this->logicalOr( - $this->equalTo(['CREATE TABLE table_name']), - $this->equalTo(['DROP TABLE table_name']) + ->with(self::logicalOr( + self::equalTo(['CREATE TABLE table_name']), + self::equalTo(['DROP TABLE table_name']) ), false, 120, true) - ->will($this->onConsecutiveCalls('test up', 'test down')); + ->will(self::onConsecutiveCalls('test up', 'test down')); $this->migrationGenerator->expects(self::once()) ->method('generateMigration') diff --git a/tests/Doctrine/Migrations/Tests/SchemaDumperTest.php b/tests/Doctrine/Migrations/Tests/SchemaDumperTest.php index 24ab9aaea6..c87e2d6a98 100644 --- a/tests/Doctrine/Migrations/Tests/SchemaDumperTest.php +++ b/tests/Doctrine/Migrations/Tests/SchemaDumperTest.php @@ -76,13 +76,13 @@ public function testDump(): void ->method('getDropTableSQL') ->willReturn('DROP TABLE test'); - $this->migrationSqlGenerator->expects($this->exactly(2)) + $this->migrationSqlGenerator->expects(self::exactly(2)) ->method('generate') - ->with($this->logicalOr( - $this->equalTo(['CREATE TABLE test']), - $this->equalTo(['DROP TABLE test']) + ->with(self::logicalOr( + self::equalTo(['CREATE TABLE test']), + self::equalTo(['DROP TABLE test']) )) - ->will($this->onConsecutiveCalls('up', 'down')); + ->will(self::onConsecutiveCalls('up', 'down')); $this->migrationGenerator->expects(self::once()) ->method('generateMigration') From 97e3a48eb36e8bdc75f9ab49d7498602519db379 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Tue, 24 Nov 2020 02:31:35 -0700 Subject: [PATCH 07/14] Add method_exists to use --- .../Migrations/Tests/Generator/ClassNameGeneratorTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php b/tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php index 03f61f3e4c..1da13899a2 100644 --- a/tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php +++ b/tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php @@ -7,6 +7,8 @@ use Doctrine\Migrations\Generator\ClassNameGenerator; use PHPUnit\Framework\TestCase; +use function method_exists; + class ClassNameGeneratorTest extends TestCase { public function testName(): void From 7ebfde3731a96c921714d5aa4a0fc1524fac9ecf Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Tue, 24 Nov 2020 14:24:16 -0700 Subject: [PATCH 08/14] Introduced new migration_organization value of 'none' to reset to false --- .../Configuration/Configuration.php | 34 ++++++++----------- .../Tests/Configuration/ConfigurationTest.php | 15 +++----- 2 files changed, 19 insertions(+), 30 deletions(-) diff --git a/lib/Doctrine/Migrations/Configuration/Configuration.php b/lib/Doctrine/Migrations/Configuration/Configuration.php index a210289d17..0f726971cb 100644 --- a/lib/Doctrine/Migrations/Configuration/Configuration.php +++ b/lib/Doctrine/Migrations/Configuration/Configuration.php @@ -17,6 +17,7 @@ */ 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'; @@ -175,29 +176,22 @@ public function isDatabasePlatformChecked(): bool return $this->checkDbPlatform; } - /** - * @param string | bool $migrationOrganization - */ - public function setMigrationOrganization($migrationOrganization): void + public function setMigrationOrganization(string $migrationOrganization): void { $this->assertNotFrozen(); - if ($migrationOrganization === false) { - $this->setMigrationsAreOrganizedByYearAndMonth(false); - - return; - } - - if (! is_string($migrationOrganization)) { - throw UnknownConfigurationValue::new('organize_migrations', $migrationOrganization); - } - - 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 b8fbb59c33..e1f8156e52 100644 --- a/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php +++ b/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTest.php @@ -81,21 +81,16 @@ public function testMigrationOrganizationWithWrongValue(): void $config->setMigrationOrganization('foo'); } - public function testMigrationOrganizationCanBeResetToFalse(): void + public function testMigrationOrganizationCanBeReset(): void { $config = new Configuration(); + $config->setMigrationOrganization(Configuration::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH); - $config->setMigrationOrganization(false); + self::assertTrue($config->areMigrationsOrganizedByYearAndMonth()); + self::assertTrue($config->areMigrationsOrganizedByYear()); + $config->setMigrationOrganization(Configuration::VERSIONS_ORGANIZATION_NONE); self::assertFalse($config->areMigrationsOrganizedByYearAndMonth()); self::assertFalse($config->areMigrationsOrganizedByYear()); } - - public function testMigrationOrganizationMustBeSetToFalseOrStringTestTrue(): void - { - $this->expectException(UnknownConfigurationValue::class); - $config = new Configuration(); - $config->setMigrationOrganization(Configuration::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH); - $config->setMigrationOrganization(true); - } } From 75e548f8ede9efdd55a9a0ae43524559525ff0f4 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Tue, 24 Nov 2020 14:29:59 -0700 Subject: [PATCH 09/14] Changed comment about space padded driver name --- .../Tests/Tools/Console/Command/StatusCommandTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php index c5657ed7a4..8d535325a2 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/StatusCommandTest.php @@ -75,7 +75,8 @@ public function testExecute(): void $lines = array_map('trim', explode("\n", trim($this->commandTester->getDisplay(true)))); if (DBALVersion::compare('2.11.0') > 0) { - $databaseDriver = 'Doctrine\DBAL\Driver\PDOSqlite\Driver '; // Trailing space bufferes outout assertion + // 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'; } From 3c4824907160f5d251af3531044265c7e1f0f30d Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Tue, 24 Nov 2020 14:42:34 -0700 Subject: [PATCH 10/14] Added composer-normalize --- .github/workflows/continuous-integration.yml | 9 ++++++ composer.json | 33 +++++++++++--------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index f60953a940..d7f6d50332 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -18,6 +18,15 @@ jobs: with: args: --from=${{ github.event.pull_request.base.sha }} + composer_normalize: + name: "Composer Normalize" + runs-on: "ubuntu-latest" + needs: + - "composer" + steps: + - name: "Composer Normalize" + run: "composer normalize --dry-run" + phpunit: name: "PHPUnit" runs-on: "ubuntu-20.04" diff --git a/composer.json b/composer.json index c79f21bea3..8d6e68cb94 100644 --- a/composer.json +++ b/composer.json @@ -25,33 +25,46 @@ ], "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": 2, + "indent-style": "space" + } + }, "autoload": { "psr-4": { "Doctrine\\Migrations\\": "lib/Doctrine/Migrations" @@ -62,14 +75,6 @@ "Doctrine\\Migrations\\Tests\\": "tests/Doctrine/Migrations/Tests" } }, - "config": { - "sort-packages": true - }, - "extra": { - "branch-alias": { - "dev-master": "3.0.x-dev" - } - }, "bin": [ "bin/doctrine-migrations" ] From 7b07dc94e336528fe080af8fc31d27d6b428166c Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Tue, 24 Nov 2020 14:50:08 -0700 Subject: [PATCH 11/14] Optimize use statements --- lib/Doctrine/Migrations/Configuration/Configuration.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Doctrine/Migrations/Configuration/Configuration.php b/lib/Doctrine/Migrations/Configuration/Configuration.php index 0f726971cb..d3e0ab3f54 100644 --- a/lib/Doctrine/Migrations/Configuration/Configuration.php +++ b/lib/Doctrine/Migrations/Configuration/Configuration.php @@ -9,8 +9,7 @@ use Doctrine\Migrations\Exception\MigrationException; use Doctrine\Migrations\Metadata\Storage\MetadataStorageConfiguration; -use function is_string; -use function strcasecmp; +use function strtolower; /** * The Configuration class is responsible for defining migration configuration information. From 2ac5b0f5fa607690edf72d83ea755d5e56324d77 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Tue, 24 Nov 2020 14:53:24 -0700 Subject: [PATCH 12/14] Add CI job for composer-normalize --- .github/workflows/continuous-integration.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index d7f6d50332..fe0002abac 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -1,4 +1,3 @@ - name: "Continuous Integration" on: @@ -21,11 +20,14 @@ jobs: composer_normalize: name: "Composer Normalize" runs-on: "ubuntu-latest" - needs: - - "composer" steps: - - name: "Composer Normalize" - run: "composer normalize --dry-run" + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - uses: "docker://ergebnis/composer-normalize-action:latest" + with: + args: "--dry-run" phpunit: name: "PHPUnit" From 64e38f6fe4c27c2a381f01517944e3d8682be969 Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Wed, 25 Nov 2020 15:39:46 -0700 Subject: [PATCH 13/14] Use ubuntu-20.04 for composer_normalize --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index fe0002abac..5824172315 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -19,7 +19,7 @@ jobs: composer_normalize: name: "Composer Normalize" - runs-on: "ubuntu-latest" + runs-on: "ubuntu-20.04" steps: - uses: actions/checkout@v2 with: From 6961ea16ee001c7848490fd35ea146c6ec3d750e Mon Sep 17 00:00:00 2001 From: Tom H Anderson Date: Thu, 26 Nov 2020 14:54:22 -0700 Subject: [PATCH 14/14] Reverted to 4 spaces in composer.json --- composer.json | 152 +++++++++++++++++++++++++------------------------- 1 file changed, 76 insertions(+), 76 deletions(-) diff --git a/composer.json b/composer.json index 8d6e68cb94..17b30da7ee 100644 --- a/composer.json +++ b/composer.json @@ -1,81 +1,81 @@ { - "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": [ - "database", - "migrations", - "dbal" - ], - "homepage": "https://www.doctrine-project.org/projects/migrations.html", - "license": "MIT", - "authors": [ - { - "name": "Benjamin Eberlei", - "email": "kontakt@beberlei.de" + "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": [ + "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" + } + ], + "require": { + "php": "^7.2", + "composer/package-versions-deprecated": "^1.8", + "doctrine/dbal": "^2.10", + "doctrine/event-manager": "^1.0", + "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" }, - { - "name": "Jonathan Wage", - "email": "jonwage@gmail.com" + "require-dev": { + "ext-pdo_sqlite": "*", + "doctrine/coding-standard": "^8.0", + "doctrine/orm": "^2.6", + "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" }, - { - "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", - "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" - }, - "require-dev": { - "ext-pdo_sqlite": "*", - "doctrine/coding-standard": "^8.0", - "doctrine/orm": "^2.6", - "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" - }, - "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" + "suggest": { + "doctrine/sql-formatter": "Allows to generate formatted SQL with the diff command.", + "symfony/yaml": "Allows the use of yaml for migration configuration files." }, - "composer-normalize": { - "indent-size": 2, - "indent-style": "space" - } - }, - "autoload": { - "psr-4": { - "Doctrine\\Migrations\\": "lib/Doctrine/Migrations" - } - }, - "autoload-dev": { - "psr-4": { - "Doctrine\\Migrations\\Tests\\": "tests/Doctrine/Migrations/Tests" - } - }, - "bin": [ - "bin/doctrine-migrations" - ] + "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" + } + }, + "autoload-dev": { + "psr-4": { + "Doctrine\\Migrations\\Tests\\": "tests/Doctrine/Migrations/Tests" + } + }, + "bin": [ + "bin/doctrine-migrations" + ] }