Skip to content

Commit 8fb3fff

Browse files
Merge branch '5.4' into 6.0
* 5.4: Fix merge [FrameworkBundle] Fix resetting container between tests
2 parents ef5fe18 + 924d579 commit 8fb3fff

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

KernelBrowser.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use Symfony\Component\HttpKernel\KernelInterface;
2323
use Symfony\Component\HttpKernel\Profiler\Profile as HttpProfile;
2424
use Symfony\Component\Security\Core\User\UserInterface;
25-
use Symfony\Contracts\Service\ResetInterface;
2625

2726
/**
2827
* Simulates a browser and makes requests to a Kernel object.
@@ -157,12 +156,8 @@ protected function doRequest(object $request): Response
157156
// avoid shutting down the Kernel if no request has been performed yet
158157
// WebTestCase::createClient() boots the Kernel but do not handle a request
159158
if ($this->hasPerformedRequest && $this->reboot) {
160-
$container = $this->kernel->getContainer();
159+
$this->kernel->boot();
161160
$this->kernel->shutdown();
162-
163-
if ($container instanceof ResetInterface) {
164-
$container->reset();
165-
}
166161
} else {
167162
$this->hasPerformedRequest = true;
168163
}

Test/KernelTestCase.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\DependencyInjection\ContainerInterface;
1616
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
1717
use Symfony\Component\HttpKernel\KernelInterface;
18-
use Symfony\Contracts\Service\ResetInterface;
1918

2019
/**
2120
* KernelTestCase is the base class for tests needing a Kernel.
@@ -35,8 +34,6 @@ abstract class KernelTestCase extends TestCase
3534

3635
protected static $booted = false;
3736

38-
private static ?ContainerInterface $kernelContainer = null;
39-
4037
protected function tearDown(): void
4138
{
4239
static::ensureKernelShutdown();
@@ -69,12 +66,11 @@ protected static function bootKernel(array $options = []): KernelInterface
6966
{
7067
static::ensureKernelShutdown();
7168

72-
static::$kernel = static::createKernel($options);
73-
static::$kernel->boot();
69+
$kernel = static::createKernel($options);
70+
$kernel->boot();
71+
self::$kernel = $kernel;
7472
static::$booted = true;
7573

76-
self::$kernelContainer = static::$kernel->getContainer();
77-
7874
return static::$kernel;
7975
}
8076

@@ -93,7 +89,7 @@ protected static function getContainer(): ContainerInterface
9389
}
9490

9591
try {
96-
return self::$kernelContainer->get('test.service_container');
92+
return self::$kernel->getContainer()->get('test.service_container');
9793
} catch (ServiceNotFoundException $e) {
9894
throw new \LogicException('Could not find service "test.service_container". Try updating the "framework.test" config to "true".', 0, $e);
9995
}
@@ -142,14 +138,9 @@ protected static function createKernel(array $options = []): KernelInterface
142138
protected static function ensureKernelShutdown()
143139
{
144140
if (null !== static::$kernel) {
141+
static::$kernel->boot();
145142
static::$kernel->shutdown();
146143
static::$booted = false;
147144
}
148-
149-
if (self::$kernelContainer instanceof ResetInterface) {
150-
self::$kernelContainer->reset();
151-
}
152-
153-
self::$kernelContainer = null;
154145
}
155146
}

Tests/KernelBrowserTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ public function testEnableRebootKernel()
5151
$client->request('GET', '/');
5252
}
5353

54+
public function testRequestAfterKernelShutdownAndPerformedRequest()
55+
{
56+
$this->expectNotToPerformAssertions();
57+
58+
$client = static::createClient(['test_case' => 'TestServiceContainer']);
59+
$client->request('GET', '/');
60+
static::ensureKernelShutdown();
61+
$client->request('GET', '/');
62+
}
63+
5464
private function getKernelMock()
5565
{
5666
$mock = $this->getMockBuilder($this->getKernelClass())

0 commit comments

Comments
 (0)