8000 [FrameworkBundle] WebTestCase KernelBrowser::getContainer null return… · symfony/framework-bundle@046984e · GitHub
[go: up one dir, main page]

Skip to content

Commit 046984e

Browse files
Simperfitnicolas-grekas
authored andcommitted
[FrameworkBundle] WebTestCase KernelBrowser::getContainer null return type
1 parent 8540acd commit 046984e

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

Test/KernelTestCas 10000 e.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,15 @@ protected static function createKernel(array $options = [])
127127
protected static function ensureKernelShutdown()
128128
{
129129
if (null !== static::$kernel) {
130-
$container = static::$kernel->getContainer();
131-
static::$kernel->shutdown();
132-
static::$booted = false;
133-
if ($container instanceof ResetInterface) {
134-
$container->reset();
130+
$isBooted = (new \ReflectionClass(static::$kernel))->getProperty('booted');
131+
$isBooted->setAccessible(true);
132+
if ($isBooted->getValue(static::$kernel)) {
133+
$container = static::$kernel->getContainer();
134+
static::$kernel->shutdown();
135+
static::$booted = false;
136+
if ($container instanceof ResetInterface) {
137+
$container->reset();
138+
}
135139
}
136140
}
137141
static::$container = null;

Tests/Functional/app/AppKernel.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Psr\Log\NullLogger;
1515
use Symfony\Component\Config\Loader\LoaderInterface;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\Component\DependencyInjection\ContainerInterface;
1718
use Symfony\Component\Filesystem\Filesystem;
1819
use Symfony\Component\HttpKernel\Kernel;
1920

@@ -96,4 +97,13 @@ protected function getKernelParameters(): array
9697

9798
return $parameters;
9899
}
100+
101+
public function getContainer(): ContainerInterface
102+
{
103+
if (!$this->booted) {
104+
throw new \LogicException('Cannot access the container on a non-booted kernel. Did you forget to boot it?');
105+
}
106+
107+
return parent::getContainer();
108+
}
99109
}

0 commit comments

Comments
 (0)
0