Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8324cd6

Browse filesBrowse files
Fix KernelTestCase compatibility for PhpUnit 8 (bis)
1 parent 9e475b6 commit 8324cd6
Copy full SHA for 8324cd6

File tree

Expand file treeCollapse file tree

2 files changed

+48
-9
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+48
-9
lines changed
+45Lines 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 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php
+3-9Lines 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 KernelShutdownOnTearDownTrait;
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
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.