Skip to content

Commit ec76ab4

Browse files
bug symfony#60564 [FrameworkBundle] ensureKernelShutdown in tearDownAfterClass (cquintana92)
This PR was merged into the 6.4 branch. Discussion ---------- [FrameworkBundle] ensureKernelShutdown in tearDownAfterClass | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | None | License | MIT This PR performs the following change: In `KernelTestCase`, the kernel is shut down after every test, as per the `static::ensureKernelShutdown()` call in the `tearDown` function. However, if one was to perform any extra code in their `tearDownAfterClass` and call `getContainer`, it would boot up a new kernel, which would then be left dangling. The main issue with that is that when the next Test class is executed, there would already be a booted kernel, so it could happen that it was pointing to dangling resources. By adding this call to `static::ensureKernelShutdown` in the `tearDownAfterClass`, we can ensure that no dangling kernels are left even after the test class has finished. Commits ------- bf9786c [FrameworkBundle] ensureKernelShutdown in tearDownAfterClass
2 parents bc88600 + bf9786c commit ec76ab4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Test;
1313

14+
use PHPUnit\Framework\Attributes\AfterClass;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\DependencyInjection\Container;
1617
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -120,8 +121,11 @@ protected static function createKernel(array $options = []): KernelInterface
120121

121122
/**
122123
* Shuts the kernel down if it was used in the test - called by the tearDown method by default.
124+
*
125+
* @afterClass
123126
*/
124-
protected static function ensureKernelShutdown()
127+
#[AfterClass]
128+
public static function ensureKernelShutdown()
125129
{
126130
if (null !== static::$kernel) {
127131
static::$kernel->boot();

0 commit comments

Comments
 (0)