1515use Symfony \Component \DependencyInjection \ContainerInterface ;
1616use Symfony \Component \DependencyInjection \Exception \ServiceNotFoundException ;
1717use Symfony \Component \HttpKernel \KernelInterface ;
18- use Symfony \Contracts \Service \ResetInterface ;
1918
2019/**
2120 * KernelTestCase is the base class for tests needing a Kernel.
@@ -35,8 +34,6 @@ abstract class KernelTestCase extends TestCase
3534
3635 protected static $ booted = false ;
3736
38- private static ?ContainerInterface $ kernelContainer = null ;
39-
4037 protected function tearDown (): void
4138 {
4239 static ::ensureKernelShutdown ();
@@ -69,12 +66,11 @@ protected static function bootKernel(array $options = []): KernelInterface
6966 {
7067 static ::ensureKernelShutdown ();
7168
72- static ::$ kernel = static ::createKernel ($ options );
73- static ::$ kernel ->boot ();
69+ $ kernel = static ::createKernel ($ options );
70+ $ kernel ->boot ();
71+ self ::$ kernel = $ kernel ;
7472 static ::$ booted = true ;
7573
76- self ::$ kernelContainer = static ::$ kernel ->getContainer ();
77-
7874 return static ::$ kernel ;
7975 }
8076
@@ -93,7 +89,7 @@ protected static function getContainer(): ContainerInterface
9389 }
9490
9591 try {
96- return self ::$ kernelContainer ->get ('test.service_container ' );
92+ return self ::$ kernel -> getContainer () ->get ('test.service_container ' );
9793 } catch (ServiceNotFoundException $ e ) {
9894 throw new \LogicException ('Could not find service "test.service_container". Try updating the "framework.test" config to "true". ' , 0 , $ e );
9995 }
@@ -142,14 +138,9 @@ protected static function createKernel(array $options = []): KernelInterface
142138 protected static function ensureKernelShutdown ()
143139 {
144140 if (null !== static ::$ kernel ) {
141+ static ::$ kernel ->boot ();
145142 static ::$ kernel ->shutdown ();
146143 static ::$ booted = false ;
147144 }
148-
149- if (self ::$ kernelContainer instanceof ResetInterface) {
150- self ::$ kernelContainer ->reset ();
151- }
152-
153- self ::$ kernelContainer = null ;
154145 }
155146}
0 commit comments