Skip to content

Commit d18a2d8

Browse files
Fix KernelTestCase compatibility for PhpUnit 8 (bis)
1 parent 9e475b6 commit d18a2d8

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

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

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

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

210212
/**
211-
* 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.
212214
*/
213215
protected static function ensureKernelShutdown()
214216
{
@@ -220,12 +222,4 @@ protected static function ensureKernelShutdown()
220222
}
221223
}
222224
}
223-
224-
/**
225-
* Clean up Kernel usage in this test.
226-
*/
227-
protected function tearDown()
228-
{
229-
static::ensureKernelShutdown();
230-
}
231225
}
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 <fabien@symfony.com>
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 who 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 KernelTestCaseTrait
24+
{
25+
protected function tearDown(): void
26+
{
27+
static::ensureKernelShutdown();
28+
}
29+
}
30+
');
31+
} else {
32+
/**
33+
* @internal
34+
*/
35+
trait KernelTestCaseTrait
36+
{
37+
/**
38+
* @return void
39+
*/
40+
protected function tearDown()
41+
{
42+
static::ensureKernelShutdown();
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)