Skip to content

Commit 0460f39

Browse files
authored
Fix Doctrine Connection service alias (Codeception#129)
1 parent 259ee0e commit 0460f39

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/Codeception/Lib/Connector/Symfony.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Codeception\Lib\Connector;
66

77
use InvalidArgumentException;
8+
use Symfony\Bundle\FrameworkBundle\Test\TestContainer;
89
use Symfony\Component\DependencyInjection\ContainerInterface;
910
use Symfony\Component\HttpFoundation\Request;
1011
use Symfony\Component\HttpFoundation\Response;
@@ -86,6 +87,7 @@ public function rebootKernel(): void
8687
}
8788
}
8889

90+
$this->persistDoctrineConnections();
8991
$this->kernel->reboot(null);
9092

9193
$this->container = $this->getContainer();
@@ -131,4 +133,28 @@ private function getService(string $serviceName): ?object
131133
}
132134
return null;
133135
}
136+
137+
private function persistDoctrineConnections()
138+
{
139+
if (!$this->container->hasParameter('doctrine.connections')) {
140+
return;
141+
}
142+
143+
if ($this->container instanceof TestContainer) {
144+
$reflectedTestContainer = new \ReflectionMethod($this->container, 'getPublicContainer');
145+
$reflectedTestContainer->setAccessible(true);
146+
$publicContainer = $reflectedTestContainer->invoke($this->container);
147+
} else {
148+
$publicContainer = $this->container;
149+
}
150+
151+
$reflectedContainer = new \ReflectionClass($publicContainer);
152+
$reflectionTarget = $reflectedContainer->hasProperty('parameters') ? $publicContainer : $publicContainer->getParameterBag();
153+
154+
$reflectedParameters = new \ReflectionProperty($reflectionTarget, 'parameters');
155+
$reflectedParameters->setAccessible(true);
156+
$parameters = $reflectedParameters->getValue($reflectionTarget);
157+
unset($parameters['doctrine.connections']);
158+
$reflectedParameters->setValue($reflectionTarget, $parameters);
159+
}
134160
}

src/Codeception/Module/Symfony.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ public function _getEntityManager()
253253
if ($container->has('doctrine.orm.default_entity_manager')) {
254254
$this->persistPermanentService('doctrine.orm.default_entity_manager');
255255
}
256-
if ($container->has('doctrine.dbal.backend_connection')) {
257-
$this->persistPermanentService('doctrine.dbal.backend_connection');
256+
if ($container->has('doctrine.dbal.default_connection')) {
257+
$this->persistPermanentService('doctrine.dbal.default_connection');
258258
}
259259
}
260260
return $this->permanentServices[$emService];

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy