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

[FrameworkBundle] Don't reset the test container but the real one instead #34078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 UPGRADE-4.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Form
FrameworkBundle
---------------

* Deprecated booting the kernel before running `WebTestCase::createClient()`.
* Deprecated calling `WebTestCase::createClient()` while a kernel has been booted, ensure the kernel is shut down before calling the method
* Deprecated support for `templating` engine in `TemplateController`, use Twig instead
* The `$parser` argument of `ControllerResolver::__construct()` and `DelegatingLoader::__construct()`
has been deprecated.
Expand Down
3 changes: 1 addition & 2 deletions 3 UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ Form
FrameworkBundle
---------------

* Dropped support for booting the kernel before running `WebTestCase::createClient()`. `createClient()` will throw an
exception if the kernel was already booted before.
* Calling `WebTestCase::createClient()` while a kernel has been booted now throws an exception, ensure the kernel is shut down before calling the method
* Removed the `framework.templating` option, configure the Twig bundle instead.
* The project dir argument of the constructor of `AssetsInstallCommand` is required.
* Removed support for `bundle:controller:action` syntax to reference controllers. Use `serviceOrFqcn::method`
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,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()`
* Deprecated calling `WebTestCase::createClient()` while a kernel has been booted, ensure the kernel is shut down before calling the method
* Deprecated `routing.loader.service`, use `routing.loader.container` instead.
* Not tagging service route loaders with `routing.route_loader` has been deprecated.
* Overriding the methods `KernelTestCase::tearDown()` and `WebTestCase::tearDown()` without the `void` return-type is deprecated.
Expand Down
25 changes: 12 additions & 13 deletions 25 src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ abstract class KernelTestCase extends TestCase
*/
protected static $container;

protected static $booted;
protected static $booted = false;

private static $kernelContainer;

private function doTearDown()
{
Expand Down Expand Up @@ -76,7 +78,7 @@ protected static function bootKernel(array $options = [])
static::$kernel->boot();
static::$booted = true;

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

return static::$kernel;
Expand Down Expand Up @@ -127,17 +129,14 @@ protected static function createKernel(array $options = [])
protected static function ensureKernelShutdown()
{
if (null !== static::$kernel) {
$isBooted = (new \ReflectionClass(static::$kernel))->getProperty('booted');
$isBooted->setAccessible(true);
if ($isBooted->getValue(static::$kernel)) {
$container = static::$kernel->getContainer();
static::$kernel->shutdown();
static::$booted = false;
if ($container instanceof ResetInterface) {
$container->reset();
}
}
static::$kernel->shutdown();
static::$booted = false;
}

if (self::$kernelContainer instanceof ResetInterface) {
self::$kernelContainer->reset();
}
static::$container = null;

static::$container = self::$kernelContainer = null;
}
}
2 changes: 1 addition & 1 deletion 2 src/Symfony/Bundle/FrameworkBundle/Test/TestContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function initialized($id): bool
*/
public function reset()
{
$this->getPublicContainer()->reset();
// ignore the call
}

/**
Expand Down
4 changes: 2 additions & 2 deletions 4 src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ private function doTearDown()
*/
protected static function createClient(array $options = [], array $server = [])
{
if (true === static::$booted) {
@trigger_error(sprintf('Booting the kernel before calling %s() is deprecated and will throw in Symfony 5.0, the kernel should only be booted once.', __METHOD__), E_USER_DEPRECATED);
if (static::$booted) {
@trigger_error(sprintf('Calling "%s()" while a kernel has been booted is deprecated since Symfony 4.4 and will throw in 5.0, ensure the kernel is shut down before calling the method.', __METHOD__), E_USER_DEPRECATED);
}

$kernel = static::bootKernel($options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected function getKernelParameters(): array

public function getContainer(): ContainerInterface
{
if (!$this->booted) {
if (!$this->container) {
throw new \LogicException('Cannot access the container on a non-booted kernel. Did you forget to boot it?');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected function getKernelParameters(): array

public function getContainer(): ContainerInterface
{
if (!$this->booted) {
if (!$this->container) {
throw new \LogicException('Cannot access the container on a non-booted kernel. Did you forget to boot it?');
}

Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ public function getProjectDir()
*/
public function getContainer()
{
if (!$this->booted) {
if (!$this->container) {
@trigger_error('Getting the container from a non-booted kernel is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.