Skip to content

Commit 5e143c1

Browse files
committed
[FrameworkBundle] WebTestCase KernelBrowser::getContainer null return type
1 parent 584c21b commit 5e143c1

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

src/Symfony/Component/HttpKernel/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ CHANGELOG
2525
* renamed `PostResponseEvent` to `TerminateEvent`
2626
* added `HttpClientKernel` for handling requests with an `HttpClientInterface` instance
2727
* added `trace_header` and `trace_level` configuration options to `HttpCache`
28+
* Getting the container from a non-booted kernel Sis deprecated.
2829

2930
4.2.0
3031
-----

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ public function getProjectDir()
361361
*/
362362
public function getContainer()
363363
{
364+
if (null === $this->container) {
365+
@trigger_error('Getting the container from a non-booted kernel is deprecated since Symfony 4.3 and will throw an exceptions in Symfony 5.0.', E_USER_DEPRECATED);
366+
}
367+
364368
return $this->container;
365369
}
366370

src/Symfony/Component/HttpKernel/KernelInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function getRootDir();
133133
/**
134134
* Gets the current container.
135135
*
136-
* @return ContainerInterface|null A ContainerInterface instance or null when the Kernel is shutdown
136+
* @return ContainerInterface A ContainerInterface instance or null when the Kernel is shutdown
137137
*/
138138
public function getContainer();
139139

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public static function tearDownAfterClass()
3636
$fs->remove(__DIR__.'/Fixtures/var');
3737
}
3838

39+
/**
40+
* @group legacy
41+
* @expectedDeprecation Getting the container from a non-booted kernel is deprecated since Symfony 4.3 and will throw an exceptions in Symfony 5.0.
42+
*/
3943
public function testConstructor()
4044
{
4145
$env = 'test_env';
@@ -49,6 +53,10 @@ public function testConstructor()
4953
$this->assertNull($kernel->getContainer());
5054
}
5155

56+
/**
57+
* @group legacy
58+
* @expectedDeprecation Getting the container from a non-booted kernel is deprecated since Symfony 4.3 and will throw an exceptions in Symfony 5.0.
59+
*/
5260
public function testClone()
5361
{
5462
$env = 'test_env';
@@ -486,6 +494,18 @@ public function testTerminateReturnsSilentlyIfKernelIsNotBooted()
486494
$kernel->terminate(Request::create('/'), new Response());
487495
}
488496

497+
/**
498+
* @group legacy
499+
* @expectedDeprecation Getting the container from a non-booted kernel is deprecated since Symfony 4.3 and will throw an exceptions in Symfony 5.0.
500+
*/
501+
public function testDeprecatedNullKernel()
502+
{
503+
$kernel = $this->getKernel();
504+
$kernel->shutdown();
505+
506+
$this->assertNull($kernel->getContainer());
507+
}
508+
489509
public function testTerminateDelegatesTerminationOnlyForTerminableInterface()
490510
{
491511
// does not implement TerminableInterface

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy