Skip to content

Commit 6ba80dc

Browse files
committed
[DI] throw an exception when the kernel has been booted twices
1 parent fe72c36 commit 6ba80dc

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
* Deprecated the `$parser` argument of `ControllerResolver::__construct()` and `DelegatingLoader::__construct()`
99
* Deprecated the `controller_name_converter` and `resolve_controller_name_subscriber` services
1010
* The `ControllerResolver` and `DelegatingLoader` classes have been marked as `final`
11+
* Deprecated booting the kernel before running `WebTestCase::createClient()`
1112

1213
4.3.0
1314
-----

Test/KernelTestCase.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ abstract class KernelTestCase extends TestCase
3737
*/
3838
protected static $container;
3939

40+
protected static $booted;
41+
4042
protected function doTearDown(): void
4143
{
4244
static::ensureKernelShutdown();
@@ -72,6 +74,7 @@ protected static function bootKernel(array $options = [])
7274

7375
static::$kernel = static::createKernel($options);
7476
static::$kernel->boot();
77+
static::$booted = true;
7578

7679
$container = static::$kernel->getContainer();
7780
static::$container = $container->has('test.service_container') ? $container->get('test.service_container') : $container;
@@ -126,6 +129,7 @@ protected static function ensureKernelShutdown()
126129
if (null !== static::$kernel) {
127130
$container = static::$kernel->getContainer();
128131
static::$kernel->shutdown();
132+
static::$booted = false;
129133
if ($container instanceof ResetInterface) {
130134
$container->reset();
131135
}

Test/WebTestCase.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ protected function doTearDown(): void
3939
*/
4040
protected static function createClient(array $options = [], array $server = [])
4141
{
42+
if (true === static::$booted) {
43+
@trigger_error(sprintf('Booting the kernel before calling %s::%s is deprecated and will throw in Symfony 5.0, the kernel should only be booted once.', __CLASS__, __METHOD__), E_USER_DEPRECATED);
44+
}
45+
4246
$kernel = static::bootKernel($options);
4347

4448
try {

Tests/Functional/SessionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public function testTwoClients($config, $insulate)
8383
$client1->insulate();
8484
}
8585

86+
$this->ensureKernelShutdown();
87+
8688
// start second client
8789
$client2 = $this->createClient(['test_case' => 'Session', 'root_config' => $config]);
8890
if ($insulate) {

0 commit comments

Comments
 (0)