|
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,7 @@ public function rebootKernel(): void
|
86 | 87 | }
|
87 | 88 | }
|
88 | 89 |
|
| 90 | + $this->persistDoctrineConnections(); |
89 | 91 | $this->kernel->reboot(null);
|
90 | 92 |
|
91 | 93 | $this->container = $this->getContainer();
|
@@ -131,4 +133,28 @@ private function getService(string $serviceName): ?object
|
131 | 133 | }
|
132 | 134 | return null;
|
133 | 135 | }
|
| 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 | + } |
134 | 160 | }
|
0 commit comments