Skip to content

Commit 6676a97

Browse files
committed
Refactor Doctrine connections persistence
1 parent 5b8dcff commit 6676a97

File tree

1 file changed

+7
-26
lines changed

1 file changed

+7
-26
lines changed

src/Codeception/Lib/Connector/Symfony.php

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
use InvalidArgumentException;
88
use LogicException;
9-
use ReflectionMethod;
10-
use ReflectionProperty;
11-
use Symfony\Bundle\FrameworkBundle\Test\TestContainer;
129
use Symfony\Component\DependencyInjection\ContainerInterface;
1310
use Symfony\Component\HttpFoundation\Response;
1411
use Symfony\Component\HttpKernel\HttpKernelBrowser;
@@ -114,32 +111,16 @@ private function getProfiler(): ?Profiler
114111

115112
private function persistDoctrineConnections(): void
116113
{
117-
if (!$this->container->hasParameter('doctrine.connections')) {
114+
$connections = $this->container->getParameter('doctrine.connections');
115+
if (!is_array($connections)) {
118116
return;
119117
}
120118

121-
if ($this->container instanceof TestContainer) {
122-
$method = new ReflectionMethod($this->container, 'getPublicContainer');
123-
$publicContainer = $method->invoke($this->container);
124-
} else {
125-
$publicContainer = $this->container;
126-
}
127-
128-
if (!is_object($publicContainer) || !method_exists($publicContainer, 'getParameterBag')) {
129-
return;
130-
}
131-
132-
$target = property_exists($publicContainer, 'parameters')
133-
? $publicContainer
134-
: $publicContainer->getParameterBag();
135-
136-
if (!is_object($target) || !property_exists($target, 'parameters')) {
137-
return;
119+
/** @var array<array-key, non-empty-string> $connections */
120+
foreach ($connections as $connectionId) {
121+
if ($this->container->has($connectionId)) {
122+
$this->persistentServices[$connectionId] = $this->container->get($connectionId);
123+
}
138124
}
139-
$prop = new ReflectionProperty($target, 'parameters');
140-
141-
$params = (array) $prop->getValue($target);
142-
unset($params['doctrine.connections']);
143-
$prop->setValue($target, $params);
144125
}
145126
}

0 commit comments

Comments
 (0)