Fix KernelTestCase compatibility for PhpUnit 8 (bis)

This commit is contained in:
Nicolas Grekas 2019-02-09 08:38:04 +01:00 committed by Fabien Potencier
parent bb54e40ca7
commit 1077df60ab
2 changed files with 48 additions and 3 deletions

View File

@ -0,0 +1,45 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Test;
use PHPUnit\Framework\TestCase;
// Auto-adapt to PHPUnit 8 that added a `void` return-type to the tearDown method
if (method_exists(\ReflectionMethod::class, 'hasReturnType') && (new \ReflectionMethod(TestCase::class, 'tearDown'))->hasReturnType()) {
eval('
/**
* @internal
*/
trait KernelShutdownOnTearDownTrait
{
protected function tearDown(): void
{
static::ensureKernelShutdown();
}
}
');
} else {
/**
* @internal
*/
trait KernelShutdownOnTearDownTrait
{
/**
* @return void
*/
protected function tearDown()
{
static::ensureKernelShutdown();
}
}
}

View File

@ -23,6 +23,8 @@ use Symfony\Component\HttpKernel\KernelInterface;
*/
abstract class KernelTestCase extends TestCase
{
use KernelShutdownOnTearDownTrait;
protected static $class;
/**
@ -208,9 +210,7 @@ abstract class KernelTestCase extends TestCase
}
/**
* @after
*
* Shuts the kernel down if it was used in the test.
* Shuts the kernel down if it was used in the test - called by the tearDown method by default.
*/
protected static function ensureKernelShutdown()
{