From 1d3cc2b3dbd6a0bfed98fb31fde1fd70ccb54d37 Mon Sep 17 00:00:00 2001 From: d-mitrofanov-v Date: Fri, 10 Jul 2026 20:28:33 +0300 Subject: [PATCH 1/2] Fix restore doctrine connections after kernel reboot --- src/Codeception/Lib/Connector/Symfony.php | 34 +++++++++++++++-------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/Codeception/Lib/Connector/Symfony.php b/src/Codeception/Lib/Connector/Symfony.php index 656583eb..7be4f5b9 100644 --- a/src/Codeception/Lib/Connector/Symfony.php +++ b/src/Codeception/Lib/Connector/Symfony.php @@ -55,8 +55,6 @@ public function rebootKernel(): void { $this->updatePersistentServices(); - $this->persistDoctrineConnections(); - if ($this->kernel instanceof Kernel) { $this->ensureKernelShutdown(); $this->kernel->boot(); @@ -72,7 +70,28 @@ public function rebootKernel(): void protected function ensureKernelShutdown(): void { $this->kernel->boot(); - $this->kernel->shutdown(); + + $kernel = $this->kernel; + (function () use ($kernel): void { + $parameters = property_exists($this, 'parameters') ? $this->parameters : null; + if (!is_array($parameters) || !array_key_exists('doctrine.connections', $parameters)) { + $kernel->shutdown(); + + return; + } + + $connections = $parameters['doctrine.connections']; + unset($parameters['doctrine.connections']); + $this->parameters = $parameters; + + try { + $kernel->shutdown(); + } finally { + $parameters = $this->parameters; + $parameters['doctrine.connections'] = $connections; + $this->parameters = $parameters; + } + })->call($kernel->getContainer()); } private function resolveContainer(): ContainerInterface @@ -98,15 +117,6 @@ private function getProfiler(): ?Profiler return null; } - private function persistDoctrineConnections(): void - { - (function (): void { - if (property_exists($this, 'parameters') && is_array($this->parameters)) { - unset($this->parameters['doctrine.connections']); - } - })->call($this->kernel->getContainer()); - } - private function updatePersistentServices(): void { foreach ($this->persistentServices as $name => $_) { From f797a36cbf3013c36c49925ced62d8d5865d7b3b Mon Sep 17 00:00:00 2001 From: Aaron Gustavo Nieves <64917965+TavoNiievez@users.noreply.github.com> Date: Fri, 10 Jul 2026 14:15:31 -0500 Subject: [PATCH 2/2] Optimize Doctrine's connection management after the kernel shuts down --- src/Codeception/Lib/Connector/Symfony.php | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/Codeception/Lib/Connector/Symfony.php b/src/Codeception/Lib/Connector/Symfony.php index 7be4f5b9..0d290ba9 100644 --- a/src/Codeception/Lib/Connector/Symfony.php +++ b/src/Codeception/Lib/Connector/Symfony.php @@ -73,23 +73,15 @@ protected function ensureKernelShutdown(): void $kernel = $this->kernel; (function () use ($kernel): void { - $parameters = property_exists($this, 'parameters') ? $this->parameters : null; - if (!is_array($parameters) || !array_key_exists('doctrine.connections', $parameters)) { + if (!property_exists($this, 'parameters') || !is_array($this->parameters)) { $kernel->shutdown(); - return; } - - $connections = $parameters['doctrine.connections']; - unset($parameters['doctrine.connections']); - $this->parameters = $parameters; - - try { - $kernel->shutdown(); - } finally { - $parameters = $this->parameters; - $parameters['doctrine.connections'] = $connections; - $this->parameters = $parameters; + $connections = $this->parameters['doctrine.connections'] ?? null; + unset($this->parameters['doctrine.connections']); + $kernel->shutdown(); + if ($connections !== null) { + $this->parameters['doctrine.connections'] = $connections; } })->call($kernel->getContainer()); }