Skip to content

Commit 6b38195

Browse files
committed
Do not close Doctrine connections until test ends
1 parent 71d3206 commit 6b38195

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
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
}

0 commit comments

Comments
 (0)