diff --git a/lib/Doctrine/Migrations/Tools/TransactionHelper.php b/lib/Doctrine/Migrations/Tools/TransactionHelper.php index bd67524581..ebd9007d8a 100644 --- a/lib/Doctrine/Migrations/Tools/TransactionHelper.php +++ b/lib/Doctrine/Migrations/Tools/TransactionHelper.php @@ -8,6 +8,8 @@ use Doctrine\Deprecations\Deprecation; use PDO; +use function method_exists; + /** * @internal */ @@ -57,10 +59,13 @@ public static function rollbackIfInTransaction(Connection $connection): void private static function inTransaction(Connection $connection): bool { - $wrappedConnection = $connection->getWrappedConnection(); + $innermostConnection = $connection; + while (method_exists($innermostConnection, 'getWrappedConnection')) { + $innermostConnection = $innermostConnection->getWrappedConnection(); + } /* Attempt to commit or rollback while no transaction is running results in an exception since PHP 8 + pdo_mysql combination */ - return ! $wrappedConnection instanceof PDO || $wrappedConnection->inTransaction(); + return ! $innermostConnection instanceof PDO || $innermostConnection->inTransaction(); } } diff --git a/phpstan-common.neon.dist b/phpstan-common.neon.dist index 7a41be19d5..92380af703 100644 --- a/phpstan-common.neon.dist +++ b/phpstan-common.neon.dist @@ -1,30 +1,35 @@ parameters: level: 7 paths: - - %currentWorkingDirectory%/lib - - %currentWorkingDirectory%/tests + - lib + - tests excludePaths: - - %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Configuration/ConfigurationTestSource/Migrations/Version123.php + - 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 + path: lib/Doctrine/Migrations/Version/SortedMigrationPlanCalculator.php - message: '~^Variable property access on SimpleXMLElement\.$~' - path: %currentWorkingDirectory%/lib/Doctrine/Migrations/Configuration/Migration/XmlFile.php + path: lib/Doctrine/Migrations/Configuration/Migration/XmlFile.php - message: '~^Call to function is_bool\(\) with bool will always evaluate to true\.$~' - path: %currentWorkingDirectory%/lib/Doctrine/Migrations/InlineParameterFormatter.php + path: 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 + path: 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 + path: tests/Doctrine/Migrations/Tests/Stub/DoctrineRegistry.php - '~Call to method getVersion\(\) of deprecated class PackageVersions\\Versions\:.*~' + # https://github.com/phpstan/phpstan/issues/5982 + - + message: '~^Cannot call method getWrappedConnection\(\) on class-string\|object\.~' + path: lib/Doctrine/Migrations/Tools/TransactionHelper.php + # Requires PHPUnit 9 - message: '~assert.*Reg~' diff --git a/tests/Doctrine/Migrations/Tests/Event/Listeners/AutoCommitListenerTest.php b/tests/Doctrine/Migrations/Tests/Event/Listeners/AutoCommitListenerTest.php index 1f285c0e55..169079604f 100644 --- a/tests/Doctrine/Migrations/Tests/Event/Listeners/AutoCommitListenerTest.php +++ b/tests/Doctrine/Migrations/Tests/Event/Listeners/AutoCommitListenerTest.php @@ -5,6 +5,7 @@ namespace Doctrine\Migrations\Tests\Event\Listeners; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\Migrations\Event\Listeners\AutoCommitListener; use Doctrine\Migrations\Event\MigrationsEventArgs; use Doctrine\Migrations\Metadata\MigrationPlanList; @@ -51,9 +52,9 @@ public function testListenerDoesFinalCommitWhenAutoCommitIsOff(): void protected function setUp(): void { - $this->conn = $this->getMockBuilder(Connection::class) - ->disableOriginalConstructor() - ->getMock(); + $this->conn = $this->createStub(Connection::class); + $driverConnection = $this->createStub(DriverConnection::class); + $this->conn->method('getWrappedConnection')->willReturn($driverConnection); $this->listener = new AutoCommitListener(); } diff --git a/tests/Doctrine/Migrations/Tests/MigratorTest.php b/tests/Doctrine/Migrations/Tests/MigratorTest.php index ce8a9f6c56..f4d0685c35 100644 --- a/tests/Doctrine/Migrations/Tests/MigratorTest.php +++ b/tests/Doctrine/Migrations/Tests/MigratorTest.php @@ -6,6 +6,7 @@ use Doctrine\Common\EventManager; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\Migrations\Configuration\Configuration; use Doctrine\Migrations\DbalMigrator; use Doctrine\Migrations\EventDispatcher; @@ -54,7 +55,10 @@ class MigratorTest extends MigrationTestCase protected function setUp(): void { - $this->conn = $this->createMock(Connection::class); + $this->conn = $this->createMock(Connection::class); + $driverConnection = $this->createStub(DriverConnection::class); + $this->conn->method('getWrappedConnection')->willReturn($driverConnection); + $this->config = new Configuration(); $this->migratorConfiguration = new MigratorConfiguration(); diff --git a/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php b/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php index b6715860e4..a35862f21e 100644 --- a/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php +++ b/tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php @@ -6,6 +6,7 @@ use Doctrine\Common\EventManager; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\Migrations\EventDispatcher; use Doctrine\Migrations\Events; use Doctrine\Migrations\Metadata\MigrationPlan; @@ -518,8 +519,10 @@ public function executeDownShouldAppendDescriptionWhenItIsNotEmpty(): void protected function setUp(): void { - $this->metadataStorage = $this->createMock(MetadataStorage::class); - $this->connection = $this->createMock(Connection::class); + $this->metadataStorage = $this->createMock(MetadataStorage::class); + $this->connection = $this->createMock(Connection::class); + $driverConnection = $this->createStub(DriverConnection::class); + $this->connection->method('getWrappedConnection')->willReturn($driverConnection); $this->schemaDiffProvider = $this->createMock(SchemaDiffProvider::class); $this->parameterFormatter = $this->createMock(ParameterFormatter::class);