diff --git a/src/Symfony/Bundle/Test/ApiTestCase.php b/src/Symfony/Bundle/Test/ApiTestCase.php index cfb576cde8e..af7aa5eaddc 100644 --- a/src/Symfony/Bundle/Test/ApiTestCase.php +++ b/src/Symfony/Bundle/Test/ApiTestCase.php @@ -36,7 +36,11 @@ abstract class ApiTestCase extends KernelTestCase */ protected static function createClient(array $kernelOptions = [], array $defaultOptions = []): Client { - if (!static::$booted) { + if (null === ($alwaysBootKernel = $kernelOptions['alwaysBootKernel'] ?? static::alwaysBootKernel())) { + trigger_deprecation('api-platform/symfony', '5.0', \sprintf('We will not boot the kernel if it is booted already. Define the kernelOptions "alwaysBootKernel" or override "%s::alwaysBootKernel" to return "true" if you want to keep the old behavior.', static::class)); + } + + if ($alwaysBootKernel ? true : !static::$booted) { static::bootKernel($kernelOptions); } @@ -99,4 +103,12 @@ protected function getIriFromResource(object $resource): ?string return $iriConverter->getIriFromResource($resource); } + + /** + * When using Alice we recommend to use "true" + */ + protected static function alwaysBootKernel(): ?bool + { + return null; + } } diff --git a/tests/Symfony/Bundle/Test/ApiTestCaseTest.php b/tests/Symfony/Bundle/Test/ApiTestCaseTest.php index 752f41e0ead..2f39d5b11ed 100644 --- a/tests/Symfony/Bundle/Test/ApiTestCaseTest.php +++ b/tests/Symfony/Bundle/Test/ApiTestCaseTest.php @@ -401,6 +401,11 @@ public function testDoNotRebootKernelOnCreateClient(): void self::$kernel = $mock; - self::createClient(); + self::createClient(['checkContainerIsBooted' => true]); + } + + protected static function checkContainerIsBooted(): ?bool + { + return false; } } diff --git a/tests/Symfony/Bundle/Test/ClientTest.php b/tests/Symfony/Bundle/Test/ClientTest.php index 25e0466ce4c..0a39f984ae8 100644 --- a/tests/Symfony/Bundle/Test/ClientTest.php +++ b/tests/Symfony/Bundle/Test/ClientTest.php @@ -170,4 +170,9 @@ public function testLoginUser(): void $client->request('GET', '/secured_dummies'); $this->assertResponseIsSuccessful(); } + + protected static function checkContainerIsBooted(): ?bool + { + return true; + } }