Skip to content

Commit 42228de

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

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/Codeception/Lib/Connector/Symfony.php

Lines changed: 23 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,28 @@ public function rebootKernel(): void
8687
}
8788
}
8889

90+
// do not close doctrine connections until test ends
91+
$connections = null;
92+
if ($this->container->hasParameter('doctrine.connections')) {
93+
$connections = $this->container->getParameter('doctrine.connections');
94+
95+
if ($this->container instanceof TestContainer) {
96+
$reflectionTestContainer = new \ReflectionMethod($this->container, 'getPublicContainer');
97+
$reflectionTestContainer->setAccessible(true);
98+
$publicContainer = $reflectionTestContainer->invoke($this->container);
99+
} else {
100+
$publicContainer = $this->container;
101+
}
102+
103+
$reflectionContainer = new \ReflectionClass($publicContainer);
104+
$reflectionTarget = $reflectionContainer->hasProperty('parameters') ? $publicContainer : $publicContainer->getParameterBag();
105+
$reflectionProperty = new \ReflectionProperty($reflectionTarget, 'parameters');
106+
$reflectionProperty->setAccessible(true);
107+
$parameters = $reflectionProperty->getValue($reflectionTarget);
108+
unset($parameters['doctrine.connections']);
109+
$reflectionProperty->setValue($reflectionTarget, $parameters);
110+
}
111+
89112
$this->kernel->reboot(null);
90113

91114
$this->container = $this->getContainer();

0 commit comments

Comments
 (0)