Skip to content

Commit 3eb3d01

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

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/Codeception/Lib/Connector/Symfony.php

Lines changed: 21 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,26 @@ 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+
if ($this->container instanceof TestContainer) {
94+
$reflectionTestContainer = new \ReflectionMethod($this->container, 'getPublicContainer');
95+
$reflectionTestContainer->setAccessible(true);
96+
$publicContainer = $reflectionTestContainer->invoke($this->container);
97+
} else {
98+
$publicContainer = $this->container;
99+
}
100+
101+
$reflectionContainer = new \ReflectionClass($publicContainer);
102+
$reflectionTarget = $reflectionContainer->hasProperty('parameters') ? $publicContainer : $publicContainer->getParameterBag();
103+
$reflectionProperty = new \ReflectionProperty($reflectionTarget, 'parameters');
104+
$reflectionProperty->setAccessible(true);
105+
$parameters = $reflectionProperty->getValue($reflectionTarget);
106+
unset($parameters['doctrine.connections']);
107+
$reflectionProperty->setValue($reflectionTarget, $parameters);
108+
}
109+
89110
$this->kernel->reboot(null);
90111

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

0 commit comments

Comments
 (0)