diff --git a/src/Codeception/Lib/Connector/Symfony.php b/src/Codeception/Lib/Connector/Symfony.php index 4dfca1fe..174b1607 100644 --- a/src/Codeception/Lib/Connector/Symfony.php +++ b/src/Codeception/Lib/Connector/Symfony.php @@ -5,6 +5,7 @@ namespace Codeception\Lib\Connector; use InvalidArgumentException; +use Symfony\Bundle\FrameworkBundle\Test\TestContainer; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -86,6 +87,7 @@ public function rebootKernel(): void } } + $this->persistDoctrineConnections(); $this->kernel->reboot(null); $this->container = $this->getContainer(); @@ -131,4 +133,28 @@ private function getService(string $serviceName): ?object } return null; } + + private function persistDoctrineConnections() + { + if (!$this->container->hasParameter('doctrine.connections')) { + return; + } + + if ($this->container instanceof TestContainer) { + $reflectedTestContainer = new \ReflectionMethod($this->container, 'getPublicContainer'); + $reflectedTestContainer->setAccessible(true); + $publicContainer = $reflectedTestContainer->invoke($this->container); + } else { + $publicContainer = $this->container; + } + + $reflectedContainer = new \ReflectionClass($publicContainer); + $reflectionTarget = $reflectedContainer->hasProperty('parameters') ? $publicContainer : $publicContainer->getParameterBag(); + + $reflectedParameters = new \ReflectionProperty($reflectionTarget, 'parameters'); + $reflectedParameters->setAccessible(true); + $parameters = $reflectedParameters->getValue($reflectionTarget); + unset($parameters['doctrine.connections']); + $reflectedParameters->setValue($reflectionTarget, $parameters); + } } diff --git a/src/Codeception/Module/Symfony.php b/src/Codeception/Module/Symfony.php index 338c4cd6..689ded03 100644 --- a/src/Codeception/Module/Symfony.php +++ b/src/Codeception/Module/Symfony.php @@ -253,8 +253,8 @@ public function _getEntityManager() if ($container->has('doctrine.orm.default_entity_manager')) { $this->persistPermanentService('doctrine.orm.default_entity_manager'); } - if ($container->has('doctrine.dbal.backend_connection')) { - $this->persistPermanentService('doctrine.dbal.backend_connection'); + if ($container->has('doctrine.dbal.default_connection')) { + $this->persistPermanentService('doctrine.dbal.default_connection'); } } return $this->permanentServices[$emService];