From 65c919b7b6518a35682d85d115945176c8157d4f Mon Sep 17 00:00:00 2001 From: David Maicher Date: Thu, 15 Feb 2024 09:20:45 +0100 Subject: [PATCH] allow not explicitly enabling savepoints with DBAL 4 --- README.md | 2 +- .../DependencyInjection/DoctrineTestCompilerPass.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3fd4f0d..b047de8 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ return [ ]; ``` -3. Starting from version 8 you need to make sure you have `use_savepoints` enabled on your doctrine DBAL configuration for all relevant connections: +3. Starting from version 8 **and only when using DBAL < 4** you need to make sure you have `use_savepoints` enabled on your doctrine DBAL configuration for all relevant connections: ```yaml doctrine: diff --git a/src/DAMA/DoctrineTestBundle/DependencyInjection/DoctrineTestCompilerPass.php b/src/DAMA/DoctrineTestBundle/DependencyInjection/DoctrineTestCompilerPass.php index ce631e6..9e7d79d 100644 --- a/src/DAMA/DoctrineTestBundle/DependencyInjection/DoctrineTestCompilerPass.php +++ b/src/DAMA/DoctrineTestBundle/DependencyInjection/DoctrineTestCompilerPass.php @@ -5,6 +5,7 @@ use DAMA\DoctrineTestBundle\Doctrine\Cache\Psr6StaticArrayCache; use DAMA\DoctrineTestBundle\Doctrine\DBAL\Middleware; use Doctrine\Common\Cache\Cache; +use Doctrine\DBAL\Connection; use Psr\Cache\CacheItemPoolInterface; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; @@ -179,6 +180,11 @@ private function validateConnectionNames(array $configNames, array $existingName private function hasSavepointsEnabled(Definition $connectionDefinition): bool { + // DBAL 4 implicitly always enables savepoints + if (!method_exists(Connection::class, 'getEventManager')) { + return true; + } + foreach ($connectionDefinition->getMethodCalls() as $call) { if ($call[0] === 'setNestTransactionsWithSavepoints' && isset($call[1][0]) && $call[1][0]) { return true;