Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

make "use_savepoints = true" no-op with DBAL 4 #1773

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/DependencyInjection/DoctrineExtension.php
Expand Up @@ -300,8 +300,15 @@
$def->setClass($options['wrapperClass']);
}

if (! empty($connection['use_savepoints'])) {
$def->addMethodCall('setNestTransactionsWithSavepoints', [$connection['use_savepoints']]);
if (isset($connection['use_savepoints'])) {
// DBAL >= 4 always has savepoints enabled. So we only need to call "setNestTransactionsWithSavepoints" for DBAL < 4
if (method_exists(Connection::class, 'getEventManager')) {
if ($connection['use_savepoints']) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

due to empty it was actually never calling setNestTransactionsWithSavepoints(false). So I kept this behavior the same

$def->addMethodCall('setNestTransactionsWithSavepoints', [$connection['use_savepoints']]);

Check warning on line 307 in src/DependencyInjection/DoctrineExtension.php

View check run for this annotation

Codecov / codecov/patch

src/DependencyInjection/DoctrineExtension.php#L306-L307

Added lines #L306 - L307 were not covered by tests
}
} elseif (! $connection['use_savepoints']) {
throw new LogicException('The "use_savepoints" option can only be set to "true" and should ideally not be set when using DBAL >= 4');

Check warning on line 310 in src/DependencyInjection/DoctrineExtension.php

View check run for this annotation

Codecov / codecov/patch

src/DependencyInjection/DoctrineExtension.php#L310

Added line #L310 was not covered by tests
}
}

$container->setDefinition(
Expand Down
4 changes: 4 additions & 0 deletions tests/DependencyInjection/AbstractDoctrineExtensionTest.php
Expand Up @@ -240,6 +240,10 @@ public function testDbalLoadSinglePrimaryReplicaConnection(): void

public function testDbalLoadSavepointsForNestedTransactions(): void
{
if (!method_exists(Connection::class, 'getEventManager')) {
self::markTestSkipped('This test requires DBAL < 4');
}

$container = $this->loadContainer('dbal_savepoints');

$calls = $container->getDefinition('doctrine.dbal.savepoints_connection')->getMethodCalls();
Expand Down
10 changes: 7 additions & 3 deletions tests/DependencyInjection/DoctrineExtensionTest.php
Expand Up @@ -554,10 +554,14 @@ public function testUseSavePointsAddMethodCallToAddSavepointsToTheConnection():
],
], $container);

$isUsingDBAL3 = method_exists(Connection::class, 'getEventManager');

$calls = $container->getDefinition('doctrine.dbal.default_connection')->getMethodCalls();
$this->assertCount(1, $calls);
$this->assertEquals('setNestTransactionsWithSavepoints', $calls[0][0]);
$this->assertTrue($calls[0][1][0]);
$this->assertCount((int) $isUsingDBAL3, $calls);
if ($isUsingDBAL3) {
$this->assertEquals('setNestTransactionsWithSavepoints', $calls[0][0]);
$this->assertTrue($calls[0][1][0]);
}
}

public function testAutoGenerateProxyClasses(): void
Expand Down