Skip to content

Commit 146c3b1

Browse files
Merge branch '4.4' into 5.4
* 4.4: [FrameworkBundle] Fix resetting container between tests
2 parents f9a2b06 + cd52737 commit 146c3b1

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
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.
@@ -168,12 +167,8 @@ protected function doRequest(object $request)
168167
// avoid shutting down the Kernel if no request has been performed yet
169168
// WebTestCase::createClient() boots the Kernel but do not handle a request
170169
if ($this->hasPerformedRequest && $this->reboot) {
171-
$container = $this->kernel->getContainer();
170+
$this->kernel->boot();
172171
$this->kernel->shutdown();
173-
174-
if ($container instanceof ResetInterface) {
175-
$container->reset();
176-
}
177172
} else {
178173
$this->hasPerformedRequest = true;
179174
}

Test/KernelTestCase.php

Lines changed: 6 additions & 11 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.
@@ -42,8 +41,6 @@ abstract class KernelTestCase extends TestCase
4241

4342
protected static $booted = false;
4443

45-
private static $kernelContainer;
46-
4744
protected function tearDown(): void
4845
{
4946
static::ensureKernelShutdown();
@@ -80,11 +77,12 @@ protected static function bootKernel(array $options = [])
8077
{
8178
static::ensureKernelShutdown();
8279

83-
static::$kernel = static::createKernel($options);
84-
static::$kernel->boot();
80+
$kernel = static::createKernel($options);
81+
$kernel->boot();
82+
self::$kernel = $kernel;
8583
static::$booted = true;
8684

87-
self::$kernelContainer = $container = static::$kernel->getContainer();
85+
$container = static::$kernel->getContainer();
8886
static::$container = $container->has('test.service_container') ? $container->get('test.service_container') : $container;
8987

9088
return static::$kernel;
@@ -156,14 +154,11 @@ protected static function createKernel(array $options = [])
156154
protected static function ensureKernelShutdown()
157155
{
158156
if (null !== static::$kernel) {
157+
static::$kernel->boot();
159158
static::$kernel->shutdown();
160159
static::$booted = false;
161160
}
162161

163-
if (self::$kernelContainer instanceof ResetInterface) {
164-
self::$kernelContainer->reset();
165-
}
166-
167-
static::$container = self::$kernelContainer = null;
162+
static::$container = null;
168163
}
169164
}

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)