Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace kernel reboot with actual boot to reset services #209

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/Codeception/Lib/Connector/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,17 @@ public function __construct(
/** @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);
}

/**
* Reboot kernel
* Reboots the kernel.
*
* Services from the list of persistent services
* are updated from service container before kernel shutdown
Expand All @@ -66,7 +64,8 @@ public function rebootKernel(): void
}

$this->persistDoctrineConnections();
$this->kernel->reboot(null);
$this->ensureKernelShutdown();
$this->kernel->boot();
$this->container = $this->getContainer();

foreach ($this->persistentServices as $serviceName => $service) {
Expand All @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down