From 4ee70f963d1a11a51b450f22b533898b22a2e1e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20M=C3=BCller?= Date: Thu, 3 Apr 2025 12:01:41 +0200 Subject: [PATCH 1/2] Replace kernel reboot with actual boot to reset services --- src/Codeception/Lib/Connector/Symfony.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Codeception/Lib/Connector/Symfony.php b/src/Codeception/Lib/Connector/Symfony.php index 44d7595a..6bfce582 100644 --- a/src/Codeception/Lib/Connector/Symfony.php +++ b/src/Codeception/Lib/Connector/Symfony.php @@ -31,18 +31,16 @@ public function __construct( parent::__construct($kernel); $this->followRedirects(); $this->container = $this->getContainer(); - $this->rebootKernel(); + $this->rebootKernel(); // Ensure the profiler exists } /** @param Request $request */ protected function doRequest(object $request): Response { - if ($this->rebootable) { - if ($this->hasPerformedRequest) { - $this->rebootKernel(); - } else { - $this->hasPerformedRequest = true; - } + if ($this->hasPerformedRequest && $this->rebootable) { + $this->rebootKernel(); + } else { + $this->hasPerformedRequest = true; } return parent::doRequest($request); @@ -66,7 +64,9 @@ public function rebootKernel(): void } $this->persistDoctrineConnections(); - $this->kernel->reboot(null); + $this->kernel->boot(); + $this->kernel->shutdown(); + $this->kernel->boot(); $this->container = $this->getContainer(); foreach ($this->persistentServices as $serviceName => $service) { From de81c286a278c26382ddf5c92b19632b09483b32 Mon Sep 17 00:00:00 2001 From: TavoNiievez Date: Wed, 9 Apr 2025 17:31:07 -0500 Subject: [PATCH 2/2] Ensure congruence with the flow in the Symfony KernelTestCase --- src/Codeception/Lib/Connector/Symfony.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Codeception/Lib/Connector/Symfony.php b/src/Codeception/Lib/Connector/Symfony.php index 6bfce582..0ea05923 100644 --- a/src/Codeception/Lib/Connector/Symfony.php +++ b/src/Codeception/Lib/Connector/Symfony.php @@ -31,7 +31,7 @@ public function __construct( parent::__construct($kernel); $this->followRedirects(); $this->container = $this->getContainer(); - $this->rebootKernel(); // Ensure the profiler exists + $this->rebootKernel(); } /** @param Request $request */ @@ -47,7 +47,7 @@ protected function doRequest(object $request): Response } /** - * Reboot kernel + * Reboots the kernel. * * Services from the list of persistent services * are updated from service container before kernel shutdown @@ -64,8 +64,7 @@ public function rebootKernel(): void } $this->persistDoctrineConnections(); - $this->kernel->boot(); - $this->kernel->shutdown(); + $this->ensureKernelShutdown(); $this->kernel->boot(); $this->container = $this->getContainer(); @@ -82,6 +81,12 @@ public function rebootKernel(): void } } + protected function ensureKernelShutdown(): void + { + $this->kernel->boot(); + $this->kernel->shutdown(); + } + private function getContainer(): ?ContainerInterface { /** @var ContainerInterface $container */ @@ -120,7 +125,9 @@ private function persistDoctrineConnections(): void } $reflectedContainer = new ReflectionClass($publicContainer); - $reflectionTarget = $reflectedContainer->hasProperty('parameters') ? $publicContainer : $publicContainer->getParameterBag(); + $reflectionTarget = $reflectedContainer->hasProperty('parameters') + ? $publicContainer + : $publicContainer->getParameterBag(); $reflectedParameters = new ReflectionProperty($reflectionTarget, 'parameters'); $reflectedParameters->setAccessible(true);