diff --git a/packages/tester-bundle/PHPUnit/Extension/KernelShutdownExtension.php b/packages/tester-bundle/PHPUnit/Extension/KernelShutdownExtension.php new file mode 100644 index 00000000..18997642 --- /dev/null +++ b/packages/tester-bundle/PHPUnit/Extension/KernelShutdownExtension.php @@ -0,0 +1,56 @@ +registerSubscribers( + new class() implements TestFinishedSubscriber { + public function notify(TestFinished $event): void + { + $test = $event->test(); + + \assert($test instanceof TestMethod); + + KernelShutdownExtension::ensureKernelShutdown($test->className()); + } + }, + new class() implements TestSuiteFinishedSubscriber { + public function notify(TestSuiteFinished $event): void + { + $class = $event->testSuite()->name(); + + KernelShutdownExtension::ensureKernelShutdown($class); + } + } + ); + } + + public static function ensureKernelShutdown(string $class): void + { + if (!class_exists($class)) { + return; + } + + $reflection = new \ReflectionClass($class); + + if ($reflection->hasMethod('ensureKernelShutdown')) { + $method = $reflection->getMethod('ensureKernelShutdown'); + $method->invoke(null); + + $reflection->getProperty('kernel')->setValue(null); + } + } +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f43eaffc..24fe8f25 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -40,5 +40,6 @@ +