Skip to content

Commit 758aef7

Browse files
bug symfony#45671 [FrameworkBundle] Ensure container is reset between tests (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [FrameworkBundle] Ensure container is reset between tests | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix symfony#45668 | License | MIT | Doc PR | - Calling boot() resets the container only is a request was handled before. Since this is not always the case here, we need to reset the container explicitly. Commits ------- 608b1dd [FrameworkBundle] Ensure container is reset between tests
2 parents c3ba272 + 608b1dd commit 758aef7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\DependencyInjection\ContainerInterface;
1616
use Symfony\Component\HttpKernel\KernelInterface;
17+
use Symfony\Contracts\Service\ResetInterface;
1718

1819
/**
1920
* KernelTestCase is the base class for tests needing a Kernel.
@@ -131,8 +132,13 @@ protected static function ensureKernelShutdown()
131132
{
132133
if (null !== static::$kernel) {
133134
static::$kernel->boot();
135+
$container = static::$kernel->getContainer();
134136
static::$kernel->shutdown();
135137
static::$booted = false;
138+
139+
if ($container instanceof ResetInterface) {
140+
$container->reset();
141+
}
136142
}
137143

138144
static::$container = null;

0 commit comments

Comments
 (0)