diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 9abe75f181..2800b5987d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -9,6 +9,7 @@ CHANGELOG * Deprecated the `controller_name_converter` and `resolve_controller_name_subscriber` services * The `ControllerResolver` and `DelegatingLoader` classes have been marked as `final` * Added support for configuring chained cache pools + * Deprecated booting the kernel before running `WebTestCase::createClient()` 4.3.0 ----- diff --git a/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php b/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php index e794b2b61d..b27778a01a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php +++ b/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php @@ -37,6 +37,8 @@ abstract class KernelTestCase extends TestCase */ protected static $container; + protected static $booted; + protected function doTearDown(): void { static::ensureKernelShutdown(); @@ -72,6 +74,7 @@ abstract class KernelTestCase extends TestCase static::$kernel = static::createKernel($options); static::$kernel->boot(); + static::$booted = true; $container = static::$kernel->getContainer(); static::$container = $container->has('test.service_container') ? $container->get('test.service_container') : $container; @@ -126,6 +129,7 @@ abstract class KernelTestCase extends TestCase if (null !== static::$kernel) { $container = static::$kernel->getContainer(); static::$kernel->shutdown(); + static::$booted = false; if ($container instanceof ResetInterface) { $container->reset(); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php b/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php index 09ab5eeb66..1bcf762c47 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php +++ b/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php @@ -39,6 +39,10 @@ abstract class WebTestCase extends KernelTestCase */ protected static function createClient(array $options = [], array $server = []) { + if (true === static::$booted) { + @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); + } + $kernel = static::bootKernel($options); try { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php index bf1b76cdc7..2924c39ce1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php @@ -83,6 +83,8 @@ class SessionTest extends WebTestCase $client1->insulate(); } + $this->ensureKernelShutdown(); + // start second client $client2 = $this->createClient(['test_case' => 'Session', 'root_config' => $config]); if ($insulate) { diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php index c38bc1a4bf..3c5bf5a719 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php @@ -58,6 +58,9 @@ class SecurityRoutingIntegrationTest extends WebTestCase public function testSecurityConfigurationForSingleIPAddress($config) { $allowedClient = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => $config], ['REMOTE_ADDR' => '10.10.10.10']); + + $this->ensureKernelShutdown(); + $barredClient = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => $config], ['REMOTE_ADDR' => '10.10.20.10']); $this->assertAllowed($allowedClient, '/secured-by-one-ip'); @@ -70,8 +73,17 @@ class SecurityRoutingIntegrationTest extends WebTestCase public function testSecurityConfigurationForMultipleIPAddresses($config) { $allowedClientA = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => $config], ['REMOTE_ADDR' => '1.1.1.1']); + + $this->ensureKernelShutdown(); + $allowedClientB = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => $config], ['REMOTE_ADDR' => '2.2.2.2']); + + $this->ensureKernelShutdown(); + $allowedClientC = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => $config], ['REMOTE_ADDR' => '203.0.113.0']); + + $this->ensureKernelShutdown(); + $barredClient = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => $config], ['REMOTE_ADDR' => '192.168.1.1']); $this->assertAllowed($allowedClientA, '/secured-by-two-ips'); @@ -91,9 +103,11 @@ class SecurityRoutingIntegrationTest extends WebTestCase { $allowedClient = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => $config], ['HTTP_USER_AGENT' => 'Firefox 1.0']); $this->assertAllowed($allowedClient, '/protected-via-expression'); + $this->ensureKernelShutdown(); $barredClient = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => $config], []); $this->assertRestricted($barredClient, '/protected-via-expression'); + $this->ensureKernelShutdown(); $allowedClient = $this->createClient(['test_case' => 'StandardFormLogin', 'root_config' => $config], []);