diff --git a/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php b/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php index 0feb15380e1c4..beccc8b0a7781 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php +++ b/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php @@ -23,6 +23,8 @@ */ abstract class KernelTestCase extends TestCase { + use KernelTestCaseTrait; + protected static $class; /** @@ -208,7 +210,7 @@ protected static function createKernel(array $options = []) } /** - * 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() { @@ -220,12 +222,4 @@ protected static function ensureKernelShutdown() } } } - - /** - * Clean up Kernel usage in this test. - */ - protected function tearDown() - { - static::ensureKernelShutdown(); - } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCaseTrait.php b/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCaseTrait.php new file mode 100644 index 0000000000000..570efccdbf74a --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCaseTrait.php @@ -0,0 +1,45 @@ + + * + * 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 who added a `void` return-type to the tearDown method + +if ((new \ReflectionMethod(TestCase::class, 'tearDown'))->hasReturnType()) { +eval(' + /** + * @internal + */ + trait KernelTestCaseTrait + { + protected function tearDown(): void + { + static::ensureKernelShutdown(); + } + } +'); +} else { + /** + * @internal + */ + trait KernelTestCaseTrait + { + /** + * @return void + */ + protected function tearDown() + { + static::ensureKernelShutdown(); + } + } +}