diff --git a/src/Symfony/Bundle/FrameworkBundle/Test/KernelShutdownOnTearDownTrait.php b/src/Symfony/Bundle/FrameworkBundle/Test/KernelShutdownOnTearDownTrait.php new file mode 100644 index 000000000000..7eb4d0726e82 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Test/KernelShutdownOnTearDownTrait.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 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(); + } + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php b/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php index 02737b391288..978f65863220 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 KernelShutdownOnTearDownTrait; + protected static $class; /** @@ -208,9 +210,7 @@ protected static function createKernel(array $options = []) } /** - * @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() {