|
5 | 5 | namespace Codeception\Lib\Connector;
|
6 | 6 |
|
7 | 7 | use InvalidArgumentException;
|
| 8 | +use Symfony\Bundle\FrameworkBundle\Test\TestContainer; |
8 | 9 | use Symfony\Component\DependencyInjection\ContainerInterface;
|
9 | 10 | use Symfony\Component\HttpFoundation\Request;
|
10 | 11 | use Symfony\Component\HttpFoundation\Response;
|
@@ -86,6 +87,28 @@ public function rebootKernel(): void
|
86 | 87 | }
|
87 | 88 | }
|
88 | 89 |
|
| 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 | + |
89 | 112 | $this->kernel->reboot(null);
|
90 | 113 |
|
91 | 114 | $this->container = $this->getContainer();
|
|
0 commit comments