Skip to content

Commit

Permalink
Merge pull request #1210 from greg0ire/fix-compat-with-dbal-3
Browse files Browse the repository at this point in the history
Look harder for a native connection
  • Loading branch information
greg0ire committed Nov 12, 2021
2 parents b4654e4 + c9e0386 commit b6e43bb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
9 changes: 7 additions & 2 deletions lib/Doctrine/Migrations/Tools/TransactionHelper.php
Expand Up @@ -8,6 +8,8 @@
use Doctrine\Deprecations\Deprecation;
use PDO;

use function method_exists;

/**
* @internal
*/
Expand Down Expand Up @@ -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();
}
}
21 changes: 13 additions & 8 deletions 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~'
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
6 changes: 5 additions & 1 deletion tests/Doctrine/Migrations/Tests/MigratorTest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 5 additions & 2 deletions tests/Doctrine/Migrations/Tests/Version/ExecutorTest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit b6e43bb

Please sign in to comment.