From f5a2714bbd575ef122de74d3991cdba96ea72a80 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Fri, 17 Sep 2021 06:42:56 +0200 Subject: [PATCH 01/15] WIP, dbal3 --- composer.json | 4 ++-- lib/Doctrine/Migrations/AbstractMigration.php | 5 ++++- lib/Doctrine/Migrations/DependencyFactory.php | 17 +++++++++++++---- .../Tools/Console/Command/ExecuteCommand.php | 5 +++-- .../Tools/Console/Command/MigrateCommand.php | 5 +++-- .../Tests/Tools/Console/ConsoleRunnerTest.php | 12 ++++++++++++ 6 files changed, 37 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 18fec970be..3e5ca82d17 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "require": { "php": "^7.2 || ^8.0", "composer/package-versions-deprecated": "^1.8", - "doctrine/dbal": "^2.11", + "doctrine/dbal": "^2.11 || ^3.0", "doctrine/deprecations": "^0.5.3", "doctrine/event-manager": "^1.0", "friendsofphp/proxy-manager-lts": "^1.0", @@ -37,7 +37,7 @@ "require-dev": { "ext-pdo_sqlite": "*", "doctrine/coding-standard": "^8.0", - "doctrine/orm": "^2.6", + "doctrine/orm": "^2.6@dev", "doctrine/persistence": "^1.3 || ^2.0", "doctrine/sql-formatter": "^1.0", "ergebnis/composer-normalize": "^2.9", diff --git a/lib/Doctrine/Migrations/AbstractMigration.php b/lib/Doctrine/Migrations/AbstractMigration.php index d09af69226..d4571e469f 100644 --- a/lib/Doctrine/Migrations/AbstractMigration.php +++ b/lib/Doctrine/Migrations/AbstractMigration.php @@ -16,6 +16,7 @@ use Doctrine\Migrations\Query\Query; use Psr\Log\LoggerInterface; +use function method_exists; use function sprintf; /** @@ -42,7 +43,9 @@ abstract class AbstractMigration public function __construct(Connection $connection, LoggerInterface $logger) { $this->connection = $connection; - $this->sm = $this->connection->getSchemaManager(); + $this->sm = method_exists($this->connection, 'createSchemaManager') + ? $this->connection->createSchemaManager() + : $this->connection->getSchemaManager(); $this->platform = $this->connection->getDatabasePlatform(); $this->logger = $logger; } diff --git a/lib/Doctrine/Migrations/DependencyFactory.php b/lib/Doctrine/Migrations/DependencyFactory.php index c91af0399f..4d31539617 100644 --- a/lib/Doctrine/Migrations/DependencyFactory.php +++ b/lib/Doctrine/Migrations/DependencyFactory.php @@ -5,6 +5,7 @@ namespace Doctrine\Migrations; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\Migrations\Configuration\Configuration; use Doctrine\Migrations\Configuration\Connection\ConnectionLoader; use Doctrine\Migrations\Configuration\EntityManager\EntityManagerLoader; @@ -51,6 +52,7 @@ use function array_key_exists; use function call_user_func; +use function method_exists; use function preg_quote; use function sprintf; @@ -231,7 +233,7 @@ public function getSchemaDumper(): SchemaDumper return new SchemaDumper( $this->getConnection()->getDatabasePlatform(), - $this->getConnection()->getSchemaManager(), + $this->getSchemaManager($this->getConnection()), $this->getMigrationGenerator(), $this->getMigrationSqlGenerator(), $excludedTables @@ -239,11 +241,18 @@ public function getSchemaDumper(): SchemaDumper }); } + private function getSchemaManager(Connection $connection): AbstractSchemaManager + { + return method_exists($connection, 'createSchemaManager') + ? $connection->createSchemaManager() + : $connection->getSchemaManager(); + } + private function getEmptySchemaProvider(): SchemaProvider { return $this->getDependency(EmptySchemaProvider::class, function (): SchemaProvider { return new EmptySchemaProvider( - $this->getConnection()->getSchemaManager() + $this->getSchemaManager($this->getConnection()) ); }); } @@ -275,7 +284,7 @@ public function getDiffGenerator(): DiffGenerator return $this->getDependency(DiffGenerator::class, function (): DiffGenerator { return new DiffGenerator( $this->getConnection()->getConfiguration(), - $this->getConnection()->getSchemaManager(), + $this->getSchemaManager($this->getConnection()), $this->getSchemaProvider(), $this->getConnection()->getDatabasePlatform(), $this->getMigrationGenerator(), @@ -290,7 +299,7 @@ public function getSchemaDiffProvider(): SchemaDiffProvider return $this->getDependency(SchemaDiffProvider::class, function (): LazySchemaDiffProvider { return LazySchemaDiffProvider::fromDefaultProxyFactoryConfiguration( new DBALSchemaDiffProvider( - $this->getConnection()->getSchemaManager(), + $this->getSchemaManager($this->getConnection()), $this->getConnection()->getDatabasePlatform() ) ); diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/ExecuteCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/ExecuteCommand.php index 77f5d9dcc8..e7e10f351c 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/ExecuteCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/ExecuteCommand.php @@ -114,9 +114,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $migratorConfigurationFactory = $this->getDependencyFactory()->getConsoleInputMigratorConfigurationFactory(); $migratorConfiguration = $migratorConfigurationFactory->getMigratorConfiguration($input); - $question = sprintf( + $databaseName = $this->getDependencyFactory()->getConnection()->getDatabase(); + $question = sprintf( 'WARNING! You are about to execute a migration in database "%s" that could result in schema changes and data loss. Are you sure you wish to continue?', - $this->getDependencyFactory()->getConnection()->getDatabase() ?? '' + $databaseName === '' || $databaseName === null ? '' : $databaseName ); if (! $migratorConfiguration->isDryRun() && ! $this->canExecute($question, $input)) { $this->io->error('Migration cancelled!'); diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php index 977b68cf69..4af73d3cd9 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php @@ -129,9 +129,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $migratorConfigurationFactory = $this->getDependencyFactory()->getConsoleInputMigratorConfigurationFactory(); $migratorConfiguration = $migratorConfigurationFactory->getMigratorConfiguration($input); - $question = sprintf( + $databaseName = $this->getDependencyFactory()->getConnection()->getDatabase(); + $question = sprintf( 'WARNING! You are about to execute a migration in database "%s" that could result in schema changes and data loss. Are you sure you wish to continue?', - $this->getDependencyFactory()->getConnection()->getDatabase() ?? '' + $databaseName === '' || $databaseName === null ? '' : $databaseName ); if (! $migratorConfiguration->isDryRun() && ! $this->canExecute($question, $input)) { $this->io->error('Migration cancelled!'); diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php index 073aba2955..1389fd3caf 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php @@ -4,6 +4,7 @@ namespace Doctrine\Migrations\Tests\Tools\Console; +use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper; use Doctrine\Migrations\DependencyFactory; use Doctrine\Migrations\Tools\Console\ConsoleRunner; use Doctrine\ORM\EntityManager; @@ -14,6 +15,7 @@ use Symfony\Component\Console\Helper\HelperSet; use function chdir; +use function class_exists; use function getcwd; use function realpath; use function sprintf; @@ -28,6 +30,11 @@ class ConsoleRunnerTest extends TestCase public function testCreateDependencyFactoryFromLegacyDbalHelper(): void { + // @phpstan-ignore-next-line + if (! class_exists(ConnectionHelper::class)) { + self::markTestSkipped('DBAL 3.0 does not provide anymore the ConnectionHelper'); + } + $dir = getcwd(); if ($dir === false) { $dir = '.'; @@ -65,6 +72,11 @@ public function testCreateDependencyFactoryFromLegacyOrmHelper(): void public function testCreateDependencyFactoryFromWrongLegacyHelper(): void { + // @phpstan-ignore-next-line + if (! class_exists(ConnectionHelper::class)) { + self::markTestSkipped('DBAL 3.0 does not provide anymore the ConnectionHelper'); + } + $this->expectException(RuntimeException::class); $dir = getcwd(); From e2f3c5129d07afb587bf6a0e6ffdbe12358ae18e Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Sun, 19 Sep 2021 08:53:37 +0200 Subject: [PATCH 02/15] xx --- .../Migrations/Tools/Console/Command/ExecuteCommand.php | 4 ++-- .../Migrations/Tools/Console/Command/MigrateCommand.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/ExecuteCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/ExecuteCommand.php index e7e10f351c..c5c802212e 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/ExecuteCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/ExecuteCommand.php @@ -114,10 +114,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $migratorConfigurationFactory = $this->getDependencyFactory()->getConsoleInputMigratorConfigurationFactory(); $migratorConfiguration = $migratorConfigurationFactory->getMigratorConfiguration($input); - $databaseName = $this->getDependencyFactory()->getConnection()->getDatabase(); + $databaseName = (string) $this->getDependencyFactory()->getConnection()->getDatabase(); $question = sprintf( 'WARNING! You are about to execute a migration in database "%s" that could result in schema changes and data loss. Are you sure you wish to continue?', - $databaseName === '' || $databaseName === null ? '' : $databaseName + $databaseName === '' ? '' : $databaseName ); if (! $migratorConfiguration->isDryRun() && ! $this->canExecute($question, $input)) { $this->io->error('Migration cancelled!'); diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php index 4af73d3cd9..aa58197b66 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php @@ -129,10 +129,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $migratorConfigurationFactory = $this->getDependencyFactory()->getConsoleInputMigratorConfigurationFactory(); $migratorConfiguration = $migratorConfigurationFactory->getMigratorConfiguration($input); - $databaseName = $this->getDependencyFactory()->getConnection()->getDatabase(); + $databaseName = (string) $this->getDependencyFactory()->getConnection()->getDatabase(); $question = sprintf( 'WARNING! You are about to execute a migration in database "%s" that could result in schema changes and data loss. Are you sure you wish to continue?', - $databaseName === '' || $databaseName === null ? '' : $databaseName + $databaseName === '' ? '' : $databaseName ); if (! $migratorConfiguration->isDryRun() && ! $this->canExecute($question, $input)) { $this->io->error('Migration cancelled!'); From 492e8c5259ce4832517d047fc92bafb61d32f7b0 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Sun, 19 Sep 2021 08:55:05 +0200 Subject: [PATCH 03/15] cast --- phpstan.neon.dist | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 40aebd634d..bf34803bdb 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -13,6 +13,10 @@ parameters: - message: '~^Variable property access on SimpleXMLElement\.$~' path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Configuration/Migration/XmlFile.php + - + message: "~^Casting to string something that's already string\.$~" + path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Tools/Console/Command/*Command.php + - message: '~^Call to function is_bool\(\) with bool will always evaluate to true\.$~' path: %currentWorkingDirectory%/lib/Doctrine/Migrations/InlineParameterFormatter.php From 8de48dad420c5df67ca2eacc894e3ea79a18d0d2 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Sat, 9 Oct 2021 21:37:56 +0200 Subject: [PATCH 04/15] getTableNames is deprecated (and not really needed for the test) --- .../Migrations/Tests/Provider/OrmSchemaProviderTest.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/Doctrine/Migrations/Tests/Provider/OrmSchemaProviderTest.php b/tests/Doctrine/Migrations/Tests/Provider/OrmSchemaProviderTest.php index caf33cd3f0..1de6cd8695 100644 --- a/tests/Doctrine/Migrations/Tests/Provider/OrmSchemaProviderTest.php +++ b/tests/Doctrine/Migrations/Tests/Provider/OrmSchemaProviderTest.php @@ -35,15 +35,6 @@ public function testCreateSchemaFetchesMetadataFromEntityManager(): void { $schema = $this->ormProvider->createSchema(); - self::assertSame( - [ - 'public.a', - 'public.b', - 'public.c', - ], - $schema->getTableNames() - ); - foreach (['a', 'b', 'c'] as $expectedTable) { $table = $schema->getTable($expectedTable); self::assertTrue($table->hasColumn('id')); From b3ca67d06107f74ae674b980faae08810832d971 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Sat, 9 Oct 2021 21:41:03 +0200 Subject: [PATCH 05/15] phpstan --- phpstan.neon.dist | 3 --- 1 file changed, 3 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index bf34803bdb..e726f7ba6b 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -13,9 +13,6 @@ parameters: - message: '~^Variable property access on SimpleXMLElement\.$~' path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Configuration/Migration/XmlFile.php - - - message: "~^Casting to string something that's already string\.$~" - path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Tools/Console/Command/*Command.php - message: '~^Call to function is_bool\(\) with bool will always evaluate to true\.$~' From 5c1c55f69c74025c4f4303e5b3373698e3ff28fa Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Sat, 9 Oct 2021 21:50:09 +0200 Subject: [PATCH 06/15] custom dbal version --- .github/workflows/continuous-integration.yml | 6 ++++++ .github/workflows/static-analysis.yml | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 393f5f8224..7c859cc1c6 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -28,6 +28,9 @@ jobs: strategy: matrix: + dbal-version: + - "^2.11" + - "^3.0" php-version: - "7.2" - "7.3" @@ -60,6 +63,9 @@ jobs: run: "composer self-update --1" if: "${{ matrix.deps == 'lowest' }}" + - name: "Require the right DBAL version" + run: "composer require doctrine/dbal:${{ matrix.dbal-version }} --no-update" + - name: "Install dependencies with Composer" uses: "ramsey/composer-install@v1" with: diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index f5eaf5ebb3..22e4750e66 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -16,6 +16,9 @@ jobs: strategy: matrix: + dbal-version: + - "^2.11" + - "^3.0" php-version: - "7.2" - "7.4" @@ -32,6 +35,9 @@ jobs: php-version: "${{ matrix.php-version }}" extensions: "pdo_sqlite" + - name: "Require the right DBAL version" + run: "composer require doctrine/dbal:${{ matrix.dbal-version }} --no-update" + - name: "Install dependencies with Composer" uses: "ramsey/composer-install@v1" with: From 98717460774476880886456735d56685303e7d36 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Sat, 9 Oct 2021 22:01:37 +0200 Subject: [PATCH 07/15] custom dbal version for phpstan --- .github/workflows/static-analysis.yml | 8 +++-- phpstan-dbal-2.neon.dist | 48 +++++++++++++++++++++++++++ phpstan-dbal-3.neon.dist | 48 +++++++++++++++++++++++++++ phpstan.neon.dist | 3 ++ 4 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 phpstan-dbal-2.neon.dist create mode 100644 phpstan-dbal-3.neon.dist diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 22e4750e66..e06e8c74b1 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -43,5 +43,9 @@ jobs: with: dependency-versions: "${{ matrix.dependencies }}" - - name: "Run a static analysis with phpstan/phpstan" - run: "vendor/bin/phpstan analyse" + - name: "Run a static analysis with phpstan/phpstan (dbal v2)" + run: "vendor/bin/phpstan analyse -c phpstan-dbal-2.neon.dist" + if: "contains(matrix.dbal-version, '^2.')" + - name: "Run a static analysis with phpstan/phpstan (dbal v3)" + run: "vendor/bin/phpstan analyse -c phpstan-dbal-3.neon.dist" + if: "contains(matrix.dbal-version, '^3.')" diff --git a/phpstan-dbal-2.neon.dist b/phpstan-dbal-2.neon.dist new file mode 100644 index 0000000000..17876055ae --- /dev/null +++ b/phpstan-dbal-2.neon.dist @@ -0,0 +1,48 @@ +parameters: + level: 7 + paths: + - %currentWorkingDirectory%/lib + - %currentWorkingDirectory%/tests + excludes_analyse: + - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTestSource/Migrations/Version123.php + ignoreErrors: + - '~Variable method call on Doctrine\\Migrations\\AbstractMigration~' + - + message: '~^Call to function in_array\(\) requires parameter #3 to be true\.$~' + path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Version/SortedMigrationPlanCalculator.php + - + message: '~^Variable property access on SimpleXMLElement\.$~' + path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Configuration/Migration/XmlFile.php + - + message: "~^Casting to string something that's already string$~" + path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Tools/Console/Command/*Command.php + + - + message: '~^Call to function is_bool\(\) with bool will always evaluate to true\.$~' + path: %currentWorkingDirectory%/lib/Doctrine/Migrations/InlineParameterFormatter.php + - + message: '~^Call to an undefined method Symfony\\Component\\Console\\Output\\OutputInterface\:\:getErrorOutput\(\)\.$~' + path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Tools/Console/ConsoleLogger.php + - + message: '~^Method Doctrine\\Migrations\\Tests\\Stub\\DoctrineRegistry::getService\(\) should return Doctrine\\Persistence\\ObjectManager but returns Doctrine\\DBAL\\Connection\|Doctrine\\ORM\\EntityManager~' + path: %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Stub/DoctrineRegistry.php + - '~Call to method getVersion\(\) of deprecated class PackageVersions\\Versions\:.*~' + - + message: '~^Instantiation of deprecated class~' + paths: + - tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-dbal/cli-config.php + - tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-wrong/cli-config.php + # Requires PHPUnit 9 + - + message: '~assert.*Reg~' + paths: + - tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php + + symfony: + console_application_loader: %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/doctrine-migrations-phpstan-app.php +includes: + - vendor/phpstan/phpstan-deprecation-rules/rules.neon + - vendor/phpstan/phpstan-phpunit/extension.neon + - vendor/phpstan/phpstan-phpunit/rules.neon + - vendor/phpstan/phpstan-strict-rules/rules.neon + - vendor/phpstan/phpstan-symfony/extension.neon diff --git a/phpstan-dbal-3.neon.dist b/phpstan-dbal-3.neon.dist new file mode 100644 index 0000000000..17876055ae --- /dev/null +++ b/phpstan-dbal-3.neon.dist @@ -0,0 +1,48 @@ +parameters: + level: 7 + paths: + - %currentWorkingDirectory%/lib + - %currentWorkingDirectory%/tests + excludes_analyse: + - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTestSource/Migrations/Version123.php + ignoreErrors: + - '~Variable method call on Doctrine\\Migrations\\AbstractMigration~' + - + message: '~^Call to function in_array\(\) requires parameter #3 to be true\.$~' + path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Version/SortedMigrationPlanCalculator.php + - + message: '~^Variable property access on SimpleXMLElement\.$~' + path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Configuration/Migration/XmlFile.php + - + message: "~^Casting to string something that's already string$~" + path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Tools/Console/Command/*Command.php + + - + message: '~^Call to function is_bool\(\) with bool will always evaluate to true\.$~' + path: %currentWorkingDirectory%/lib/Doctrine/Migrations/InlineParameterFormatter.php + - + message: '~^Call to an undefined method Symfony\\Component\\Console\\Output\\OutputInterface\:\:getErrorOutput\(\)\.$~' + path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Tools/Console/ConsoleLogger.php + - + message: '~^Method Doctrine\\Migrations\\Tests\\Stub\\DoctrineRegistry::getService\(\) should return Doctrine\\Persistence\\ObjectManager but returns Doctrine\\DBAL\\Connection\|Doctrine\\ORM\\EntityManager~' + path: %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Stub/DoctrineRegistry.php + - '~Call to method getVersion\(\) of deprecated class PackageVersions\\Versions\:.*~' + - + message: '~^Instantiation of deprecated class~' + paths: + - tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-dbal/cli-config.php + - tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-wrong/cli-config.php + # Requires PHPUnit 9 + - + message: '~assert.*Reg~' + paths: + - tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php + + symfony: + console_application_loader: %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/doctrine-migrations-phpstan-app.php +includes: + - vendor/phpstan/phpstan-deprecation-rules/rules.neon + - vendor/phpstan/phpstan-phpunit/extension.neon + - vendor/phpstan/phpstan-phpunit/rules.neon + - vendor/phpstan/phpstan-strict-rules/rules.neon + - vendor/phpstan/phpstan-symfony/extension.neon diff --git a/phpstan.neon.dist b/phpstan.neon.dist index e726f7ba6b..17876055ae 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -13,6 +13,9 @@ parameters: - message: '~^Variable property access on SimpleXMLElement\.$~' path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Configuration/Migration/XmlFile.php + - + message: "~^Casting to string something that's already string$~" + path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Tools/Console/Command/*Command.php - message: '~^Call to function is_bool\(\) with bool will always evaluate to true\.$~' From c3a2db4621c1ca5d9d4d3086c9aec2e0890207b1 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Sat, 9 Oct 2021 22:05:02 +0200 Subject: [PATCH 08/15] xx --- .github/workflows/continuous-integration.yml | 2 +- .github/workflows/static-analysis.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 7c859cc1c6..77382da368 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -32,7 +32,7 @@ jobs: - "^2.11" - "^3.0" php-version: - - "7.2" +# - "7.2" - "7.3" - "7.4" - "8.0" diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index e06e8c74b1..fe9a50591f 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -20,7 +20,7 @@ jobs: - "^2.11" - "^3.0" php-version: - - "7.2" +# - "7.2" - "7.4" - "8.0" From 6f362ecf5e5b6747382ba69e2650e4650b30e2a9 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Sat, 9 Oct 2021 22:06:59 +0200 Subject: [PATCH 09/15] xx --- phpstan-dbal-2.neon.dist | 2 +- phpstan-dbal-3.neon.dist | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/phpstan-dbal-2.neon.dist b/phpstan-dbal-2.neon.dist index 17876055ae..22ea3cfa93 100644 --- a/phpstan-dbal-2.neon.dist +++ b/phpstan-dbal-2.neon.dist @@ -14,7 +14,7 @@ parameters: message: '~^Variable property access on SimpleXMLElement\.$~' path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Configuration/Migration/XmlFile.php - - message: "~^Casting to string something that's already string$~" + message: "~^Casting to string something that's already string~" path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Tools/Console/Command/*Command.php - diff --git a/phpstan-dbal-3.neon.dist b/phpstan-dbal-3.neon.dist index 17876055ae..e726f7ba6b 100644 --- a/phpstan-dbal-3.neon.dist +++ b/phpstan-dbal-3.neon.dist @@ -13,9 +13,6 @@ parameters: - message: '~^Variable property access on SimpleXMLElement\.$~' path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Configuration/Migration/XmlFile.php - - - message: "~^Casting to string something that's already string$~" - path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Tools/Console/Command/*Command.php - message: '~^Call to function is_bool\(\) with bool will always evaluate to true\.$~' From aa1ef0d4015d902a4ae6a836ea44341a9bb54cdb Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Sat, 9 Oct 2021 22:17:30 +0200 Subject: [PATCH 10/15] stop using deprecated dbal exception --- lib/Doctrine/Migrations/AbstractMigration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/Migrations/AbstractMigration.php b/lib/Doctrine/Migrations/AbstractMigration.php index d4571e469f..c06d881940 100644 --- a/lib/Doctrine/Migrations/AbstractMigration.php +++ b/lib/Doctrine/Migrations/AbstractMigration.php @@ -5,7 +5,7 @@ namespace Doctrine\Migrations; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception as DBALException; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\Schema; From 79f548c24e098dc8ccd78d2f65e1db4b4028837c Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Sat, 9 Oct 2021 22:29:11 +0200 Subject: [PATCH 11/15] dep --- phpstan-dbal-3.neon.dist | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/phpstan-dbal-3.neon.dist b/phpstan-dbal-3.neon.dist index e726f7ba6b..5a73914ec5 100644 --- a/phpstan-dbal-3.neon.dist +++ b/phpstan-dbal-3.neon.dist @@ -3,7 +3,8 @@ parameters: paths: - %currentWorkingDirectory%/lib - %currentWorkingDirectory%/tests - excludes_analyse: + excludePaths: + - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTestSource/Migrations/Version123.php ignoreErrors: - '~Variable method call on Doctrine\\Migrations\\AbstractMigration~' @@ -13,10 +14,12 @@ parameters: - message: '~^Variable property access on SimpleXMLElement\.$~' path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Configuration/Migration/XmlFile.php - + - '~^Call to deprecated method getSchemaManager\(\) of class Doctrine\\DBAL\\Connection~' - message: '~^Call to function is_bool\(\) with bool will always evaluate to true\.$~' path: %currentWorkingDirectory%/lib/Doctrine/Migrations/InlineParameterFormatter.php + - '~Doctrine\\DBAL\\Tools\\Console\\Helper\\ConnectionHelper not found~' + - '~unknown class Doctrine\\DBAL\\Tools\\Console\\Helper\\ConnectionHelper~' - message: '~^Call to an undefined method Symfony\\Component\\Console\\Output\\OutputInterface\:\:getErrorOutput\(\)\.$~' path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Tools/Console/ConsoleLogger.php @@ -24,8 +27,9 @@ parameters: message: '~^Method Doctrine\\Migrations\\Tests\\Stub\\DoctrineRegistry::getService\(\) should return Doctrine\\Persistence\\ObjectManager but returns Doctrine\\DBAL\\Connection\|Doctrine\\ORM\\EntityManager~' path: %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Stub/DoctrineRegistry.php - '~Call to method getVersion\(\) of deprecated class PackageVersions\\Versions\:.*~' + - "~Call to function method_exists\\(\\) with Doctrine\\\\DBAL\\\\Connection and 'createSchemaManager' will always evaluate to true~" - - message: '~^Instantiation of deprecated class~' + message: '~^Parameter.* class Symfony\\Component\\Console\\Helper\\HelperSet constructor expects ~' paths: - tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-dbal/cli-config.php - tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-wrong/cli-config.php From 9d924723fa8d7665e5fa0f1fefedb422df03cf11 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Sat, 9 Oct 2021 22:31:12 +0200 Subject: [PATCH 12/15] aaa --- .github/workflows/continuous-integration.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 77382da368..0e10afa670 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -65,6 +65,7 @@ jobs: - name: "Require the right DBAL version" run: "composer require doctrine/dbal:${{ matrix.dbal-version }} --no-update" + if: "${{ matrix.dbal-version }}" - name: "Install dependencies with Composer" uses: "ramsey/composer-install@v1" From d9647b8ce36e3cd411b1fdc2407693602db459c3 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Sat, 9 Oct 2021 23:15:28 +0200 Subject: [PATCH 13/15] exclude --- .github/workflows/continuous-integration.yml | 5 ++++- .github/workflows/static-analysis.yml | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 0e10afa670..b337bfaacb 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -32,7 +32,7 @@ jobs: - "^2.11" - "^3.0" php-version: -# - "7.2" + - "7.2" - "7.3" - "7.4" - "8.0" @@ -41,6 +41,9 @@ jobs: include: - deps: "lowest" php-version: "7.2" + exclude: + - dbal-version: "^3.0" + php-version: "7.2" steps: - name: "Checkout" diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index fe9a50591f..029dc0c3f3 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -20,9 +20,12 @@ jobs: - "^2.11" - "^3.0" php-version: -# - "7.2" + - "7.2" - "7.4" - "8.0" + exclude: + - dbal-version: "^3.0" + php-version: "7.2" steps: - name: "Checkout code" From 754e7444e46404beebfff58636094269ce0e1c6f Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Wed, 13 Oct 2021 09:03:34 +0200 Subject: [PATCH 14/15] use phpstan includes --- phpstan.neon.dist => phpstan-common.neon.dist | 11 +--- phpstan-dbal-2.neon.dist | 43 +++------------ phpstan-dbal-3.neon.dist | 52 +++++-------------- .../Tests/Tools/Console/ConsoleRunnerTest.php | 2 - 4 files changed, 23 insertions(+), 85 deletions(-) rename phpstan.neon.dist => phpstan-common.neon.dist (81%) diff --git a/phpstan.neon.dist b/phpstan-common.neon.dist similarity index 81% rename from phpstan.neon.dist rename to phpstan-common.neon.dist index 17876055ae..7a41be19d5 100644 --- a/phpstan.neon.dist +++ b/phpstan-common.neon.dist @@ -3,7 +3,7 @@ parameters: paths: - %currentWorkingDirectory%/lib - %currentWorkingDirectory%/tests - excludes_analyse: + excludePaths: - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTestSource/Migrations/Version123.php ignoreErrors: - '~Variable method call on Doctrine\\Migrations\\AbstractMigration~' @@ -13,9 +13,6 @@ parameters: - message: '~^Variable property access on SimpleXMLElement\.$~' path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Configuration/Migration/XmlFile.php - - - message: "~^Casting to string something that's already string$~" - path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Tools/Console/Command/*Command.php - message: '~^Call to function is_bool\(\) with bool will always evaluate to true\.$~' @@ -27,11 +24,7 @@ parameters: message: '~^Method Doctrine\\Migrations\\Tests\\Stub\\DoctrineRegistry::getService\(\) should return Doctrine\\Persistence\\ObjectManager but returns Doctrine\\DBAL\\Connection\|Doctrine\\ORM\\EntityManager~' path: %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Stub/DoctrineRegistry.php - '~Call to method getVersion\(\) of deprecated class PackageVersions\\Versions\:.*~' - - - message: '~^Instantiation of deprecated class~' - paths: - - tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-dbal/cli-config.php - - tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-wrong/cli-config.php + # Requires PHPUnit 9 - message: '~assert.*Reg~' diff --git a/phpstan-dbal-2.neon.dist b/phpstan-dbal-2.neon.dist index 22ea3cfa93..ede0697c76 100644 --- a/phpstan-dbal-2.neon.dist +++ b/phpstan-dbal-2.neon.dist @@ -1,48 +1,19 @@ +includes: + - phpstan-common.neon.dist + parameters: - level: 7 - paths: - - %currentWorkingDirectory%/lib - - %currentWorkingDirectory%/tests - excludes_analyse: - - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTestSource/Migrations/Version123.php ignoreErrors: - - '~Variable method call on Doctrine\\Migrations\\AbstractMigration~' - - - message: '~^Call to function in_array\(\) requires parameter #3 to be true\.$~' - path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Version/SortedMigrationPlanCalculator.php + - - message: '~^Variable property access on SimpleXMLElement\.$~' - path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Configuration/Migration/XmlFile.php + message: '~^Fetching class constant class of deprecated class Doctrine\\DBAL\\Tools\\Console\\Helper\\ConnectionHelper~' + path: %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php + - message: "~^Casting to string something that's already string~" path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Tools/Console/Command/*Command.php - - - message: '~^Call to function is_bool\(\) with bool will always evaluate to true\.$~' - path: %currentWorkingDirectory%/lib/Doctrine/Migrations/InlineParameterFormatter.php - - - message: '~^Call to an undefined method Symfony\\Component\\Console\\Output\\OutputInterface\:\:getErrorOutput\(\)\.$~' - path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Tools/Console/ConsoleLogger.php - - - message: '~^Method Doctrine\\Migrations\\Tests\\Stub\\DoctrineRegistry::getService\(\) should return Doctrine\\Persistence\\ObjectManager but returns Doctrine\\DBAL\\Connection\|Doctrine\\ORM\\EntityManager~' - path: %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Stub/DoctrineRegistry.php - - '~Call to method getVersion\(\) of deprecated class PackageVersions\\Versions\:.*~' - message: '~^Instantiation of deprecated class~' paths: - tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-dbal/cli-config.php - tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-wrong/cli-config.php - # Requires PHPUnit 9 - - - message: '~assert.*Reg~' - paths: - - tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php - - symfony: - console_application_loader: %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/doctrine-migrations-phpstan-app.php -includes: - - vendor/phpstan/phpstan-deprecation-rules/rules.neon - - vendor/phpstan/phpstan-phpunit/extension.neon - - vendor/phpstan/phpstan-phpunit/rules.neon - - vendor/phpstan/phpstan-strict-rules/rules.neon - - vendor/phpstan/phpstan-symfony/extension.neon diff --git a/phpstan-dbal-3.neon.dist b/phpstan-dbal-3.neon.dist index 5a73914ec5..f84ec08447 100644 --- a/phpstan-dbal-3.neon.dist +++ b/phpstan-dbal-3.neon.dist @@ -1,49 +1,25 @@ +includes: + - phpstan-common.neon.dist + parameters: - level: 7 - paths: - - %currentWorkingDirectory%/lib - - %currentWorkingDirectory%/tests - excludePaths: - - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php - - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTestSource/Migrations/Version123.php + ignoreErrors: - - '~Variable method call on Doctrine\\Migrations\\AbstractMigration~' - - - message: '~^Call to function in_array\(\) requires parameter #3 to be true\.$~' - path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Version/SortedMigrationPlanCalculator.php - - - message: '~^Variable property access on SimpleXMLElement\.$~' - path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Configuration/Migration/XmlFile.php - - '~^Call to deprecated method getSchemaManager\(\) of class Doctrine\\DBAL\\Connection~' - - - message: '~^Call to function is_bool\(\) with bool will always evaluate to true\.$~' - path: %currentWorkingDirectory%/lib/Doctrine/Migrations/InlineParameterFormatter.php - - '~Doctrine\\DBAL\\Tools\\Console\\Helper\\ConnectionHelper not found~' - - '~unknown class Doctrine\\DBAL\\Tools\\Console\\Helper\\ConnectionHelper~' - - - message: '~^Call to an undefined method Symfony\\Component\\Console\\Output\\OutputInterface\:\:getErrorOutput\(\)\.$~' - path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Tools/Console/ConsoleLogger.php - - - message: '~^Method Doctrine\\Migrations\\Tests\\Stub\\DoctrineRegistry::getService\(\) should return Doctrine\\Persistence\\ObjectManager but returns Doctrine\\DBAL\\Connection\|Doctrine\\ORM\\EntityManager~' - path: %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Stub/DoctrineRegistry.php - - '~Call to method getVersion\(\) of deprecated class PackageVersions\\Versions\:.*~' - "~Call to function method_exists\\(\\) with Doctrine\\\\DBAL\\\\Connection and 'createSchemaManager' will always evaluate to true~" + - '~^Call to deprecated method getSchemaManager\(\) of class Doctrine\\DBAL\\Connection~' - message: '~^Parameter.* class Symfony\\Component\\Console\\Helper\\HelperSet constructor expects ~' paths: - tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-dbal/cli-config.php - tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-wrong/cli-config.php - # Requires PHPUnit 9 - - message: '~assert.*Reg~' + message: '~^Class Doctrine\\DBAL\\Tools\\Console\\Helper\\ConnectionHelper not found~' + path: lib/Doctrine/Migrations/Tools/Console/ConsoleRunner.php + - + message: '~^Call to method getConnection\(\) on an unknown class Doctrine\\DBAL\\Tools\\Console\\Helper\\ConnectionHelper~' + path: lib/Doctrine/Migrations/Tools/Console/ConsoleRunner.php + - + message: '~Instantiated class Doctrine\\DBAL\\Tools\\Console\\Helper\\ConnectionHelper not found~' paths: - - tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php + - tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-dbal/cli-config.php + - tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-wrong/cli-config.php - symfony: - console_application_loader: %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/doctrine-migrations-phpstan-app.php -includes: - - vendor/phpstan/phpstan-deprecation-rules/rules.neon - - vendor/phpstan/phpstan-phpunit/extension.neon - - vendor/phpstan/phpstan-phpunit/rules.neon - - vendor/phpstan/phpstan-strict-rules/rules.neon - - vendor/phpstan/phpstan-symfony/extension.neon diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php index 1389fd3caf..3498dab0fd 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php @@ -30,7 +30,6 @@ class ConsoleRunnerTest extends TestCase public function testCreateDependencyFactoryFromLegacyDbalHelper(): void { - // @phpstan-ignore-next-line if (! class_exists(ConnectionHelper::class)) { self::markTestSkipped('DBAL 3.0 does not provide anymore the ConnectionHelper'); } @@ -72,7 +71,6 @@ public function testCreateDependencyFactoryFromLegacyOrmHelper(): void public function testCreateDependencyFactoryFromWrongLegacyHelper(): void { - // @phpstan-ignore-next-line if (! class_exists(ConnectionHelper::class)) { self::markTestSkipped('DBAL 3.0 does not provide anymore the ConnectionHelper'); } From 58946ac918aa16b72347f5366203a1587155b7a0 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Thu, 14 Oct 2021 22:00:33 +0200 Subject: [PATCH 15/15] remove @dev from doctrine/orm --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3e5ca82d17..1e675582bc 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "require-dev": { "ext-pdo_sqlite": "*", "doctrine/coding-standard": "^8.0", - "doctrine/orm": "^2.6@dev", + "doctrine/orm": "^2.6", "doctrine/persistence": "^1.3 || ^2.0", "doctrine/sql-formatter": "^1.0", "ergebnis/composer-normalize": "^2.9",