Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1077df6

Browse files
nicolas-grekasfabpot
authored andcommitted
Fix KernelTestCase compatibility for PhpUnit 8 (bis)
1 parent bb54e40 commit 1077df6

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Test;
13+
14+
use PHPUnit\Framework\TestCase;
15+
16+
// Auto-adapt to PHPUnit 8 that added a `void` return-type to the tearDown method
17+
18+
if (method_exists(\ReflectionMethod::class, 'hasReturnType') && (new \ReflectionMethod(TestCase::class, 'tearDown'))->hasReturnType()) {
19+
eval('
20+
/**
21+
* @internal
22+
*/
23+
trait KernelShutdownOnTearDownTrait
24+
{
25+
protected function tearDown(): void
26+
{
27+
static::ensureKernelShutdown();
28+
}
29+
}
30+
');
31+
} else {
32+
/**
33+
* @internal
34+
*/
35+
trait KernelShutdownOnTearDownTrait
36+
{
37+
/**
38+
* @return void
39+
*/
40+
protected function tearDown()
41+
{
42+
static::ensureKernelShutdown();
43+
}
44+
}
45+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
abstract class KernelTestCase extends TestCase
2525
{
26+
use KernelShutdownOnTearDownTrait;
27+
2628
protected static $class;
2729

2830
/**
@@ -208,9 +210,7 @@ protected static function createKernel(array $options = [])
208210
}
209211

210212
/**
211-
* @after
212-
*
213-
* Shuts the kernel down if it was used in the test.
213+
* Shuts the kernel down if it was used in the test - called by the tearDown method by default.
214214
*/
215215
protected static function ensureKernelShutdown()
216216
{

0 commit comments

Comments
 (0)