Skip to content

Commit 6dba6df

Browse files
committed
bug #32056 [DI] deprecate booting the kernel twices (Simperfit)
This PR was merged into the 4.4 branch. Discussion ---------- [DI] deprecate booting the kernel twices | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | yes <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #31233 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | ? <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/roadmap): - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against branch 4.4. - Legacy code removals go to the master branch. --> This adds a check to see if the kernel has been booted twices in a single test, and throw a deprecation Commits ------- 905bec4577 [DI] throw an exception when the kernel has been booted twices
2 parents a860353 + 6ba80dc commit 6dba6df

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
@@ -9,6 +9,7 @@ CHANGELOG
99
* Deprecated the `controller_name_converter` and `resolve_controller_name_subscriber` services
1010
* The `ControllerResolver` and `DelegatingLoader` classes have been marked as `final`
1111
* Added support for configuring chained cache pools
12+
* Deprecated booting the kernel before running `WebTestCase::createClient()`
1213

1314
4.3.0
1415
-----

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)