Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cd52737

Browse filesBrowse files
[FrameworkBundle] Fix resetting container between tests
1 parent 353bc8a commit cd52737
Copy full SHA for cd52737

File tree

Expand file treeCollapse file tree

3 files changed

+17
-17
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+17
-17
lines changed

‎Client.php

Copy file name to clipboardExpand all lines: Client.php
+1-6Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Symfony\Component\HttpKernel\HttpKernelBrowser;
2020
use Symfony\Component\HttpKernel\KernelInterface;
2121
use Symfony\Component\HttpKernel\Profiler\Profile as HttpProfile;
22-
use Symfony\Contracts\Service\ResetInterface;
2322

2423
/**
2524
* Client simulates a browser and makes requests to a Kernel object.
@@ -117,12 +116,8 @@ protected function doRequest($request)
117116
// avoid shutting down the Kernel if no request has been performed yet
118117
// WebTestCase::createClient() boots the Kernel but do not handle a request
119118
if ($this->hasPerformedRequest && $this->reboot) {
120-
$container = $this->kernel->getContainer();
119+
$this->kernel->boot();
121120
$this->kernel->shutdown();
122-
123-
if ($container instanceof ResetInterface) {
124-
$container->reset();
125-
}
126121
} else {
127122
$this->hasPerformedRequest = true;
128123
}

‎Test/KernelTestCase.php

Copy file name to clipboardExpand all lines: Test/KernelTestCase.php
+6-11Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\DependencyInjection\ContainerInterface;
1616
use Symfony\Component\HttpKernel\KernelInterface;
17-
use Symfony\Contracts\Service\ResetInterface;
1817

1918
/**
2019
* KernelTestCase is the base class for tests needing a Kernel.
@@ -39,8 +38,6 @@ abstract class KernelTestCase extends TestCase
3938

4039
protected static $booted = false;
4140

42-
private static $kernelContainer;
43-
4441
private function doTearDown()
4542
{
4643
static::ensureKernelShutdown();
@@ -77,11 +74,12 @@ protected static function bootKernel(array $options = [])
7774
{
7875
static::ensureKernelShutdown();
7976

80-
static::$kernel = static::createKernel($options);
81-
static::$kernel->boot();
77+
$kernel = static::createKernel($options);
78+
$kernel->boot();
79+
self::$kernel = $kernel;
8280
static::$booted = true;
8381

84-
self::$kernelContainer = $container = static::$kernel->getContainer();
82+
$container = static::$kernel->getContainer();
8583
static::$container = $container->has('test.service_container') ? $container->get('test.service_container') : $container;
8684

8785
return static::$kernel;
@@ -132,14 +130,11 @@ protected static function createKernel(array $options = [])
132130
protected static function ensureKernelShutdown()
133131
{
134132
if (null !== static::$kernel) {
133+
static::$kernel->boot();
135134
static::$kernel->shutdown();
136135
static::$booted = false;
137136
}
138137

139-
if (self::$kernelContainer instanceof ResetInterface) {
140-
self::$kernelContainer->reset();
141-
}
142-
143-
static::$container = self::$kernelContainer = null;
138+
static::$container = null;
144139
}
145140
}

‎Tests/KernelBrowserTest.php

Copy file name to clipboardExpand all lines: Tests/KernelBrowserTest.php
+10Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.