Skip to content

Commit 8336768

Browse files
committed
Ensure congruence with the flow in the Symfony KernelTestCase
1 parent 4ee70f9 commit 8336768

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/Codeception/Lib/Connector/Symfony.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\HttpFoundation\Response;
1515
use Symfony\Component\HttpKernel\HttpKernelBrowser;
1616
use Symfony\Component\HttpKernel\Kernel;
17+
use Symfony\Contracts\Service\ResetInterface;
1718
use Symfony\Component\HttpKernel\Profiler\Profiler;
1819
use function array_keys;
1920
use function codecept_debug;
@@ -31,7 +32,7 @@ public function __construct(
3132
parent::__construct($kernel);
3233
$this->followRedirects();
3334
$this->container = $this->getContainer();
34-
$this->rebootKernel(); // Ensure the profiler exists
35+
$this->rebootKernel();
3536
}
3637

3738
/** @param Request $request */
@@ -47,7 +48,7 @@ protected function doRequest(object $request): Response
4748
}
4849

4950
/**
50-
* Reboot kernel
51+
* Reboots the kernel.
5152
*
5253
* Services from the list of persistent services
5354
* are updated from service container before kernel shutdown
@@ -64,8 +65,7 @@ public function rebootKernel(): void
6465
}
6566

6667
$this->persistDoctrineConnections();
67-
$this->kernel->boot();
68-
$this->kernel->shutdown();
68+
$this->ensureKernelShutdown();
6969
$this->kernel->boot();
7070
$this->container = $this->getContainer();
7171

@@ -82,6 +82,22 @@ public function rebootKernel(): void
8282
}
8383
}
8484

85+
protected function ensureKernelShutdown(): void
86+
{
87+
$this->kernel->boot();
88+
$container = $this->kernel->getContainer();
89+
90+
if ($container->has('services_resetter')) {
91+
$container->get('services_resetter');
92+
}
93+
94+
$this->kernel->shutdown();
95+
96+
if ($container instanceof ResetInterface) {
97+
$container->reset();
98+
}
99+
}
100+
85101
private function getContainer(): ?ContainerInterface
86102
{
87103
/** @var ContainerInterface $container */
@@ -120,12 +136,16 @@ private function persistDoctrineConnections(): void
120136
}
121137

122138
$reflectedContainer = new ReflectionClass($publicContainer);
123-
$reflectionTarget = $reflectedContainer->hasProperty('parameters') ? $publicContainer : $publicContainer->getParameterBag();
139+
$reflectionTarget = $reflectedContainer->hasProperty('parameters')
140+
? $publicContainer
141+
: $publicContainer->getParameterBag();
124142

125143
$reflectedParameters = new ReflectionProperty($reflectionTarget, 'parameters');
126144
$reflectedParameters->setAccessible(true);
127145
$parameters = $reflectedParameters->getValue($reflectionTarget);
128-
unset($parameters['doctrine.connections']);
146+
if (array_key_exists('doctrine.connections', $parameters)) {
147+
$parameters['doctrine.connections'] = [];
148+
}
129149
$reflectedParameters->setValue($reflectionTarget, $parameters);
130150
}
131151
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy