15
15
use Symfony \Component \DependencyInjection \ContainerInterface ;
16
16
use Symfony \Component \DependencyInjection \Exception \ServiceNotFoundException ;
17
17
use Symfony \Component \HttpKernel \KernelInterface ;
18
- use Symfony \Contracts \Service \ResetInterface ;
19
18
20
19
/**
21
20
* KernelTestCase is the base class for tests needing a Kernel.
@@ -35,8 +34,6 @@ abstract class KernelTestCase extends TestCase
35
34
36
35
protected static $ booted = false ;
37
36
38
- private static ?ContainerInterface $ kernelContainer = null ;
39
-
40
37
protected function tearDown (): void
41
38
{
42
39
static ::ensureKernelShutdown ();
@@ -69,12 +66,11 @@ protected static function bootKernel(array $options = []): KernelInterface
69
66
{
70
67
static ::ensureKernelShutdown ();
71
68
72
- static ::$ kernel = static ::createKernel ($ options );
73
- static ::$ kernel ->boot ();
69
+ $ kernel = static ::createKernel ($ options );
70
+ $ kernel ->boot ();
71
+ self ::$ kernel = $ kernel ;
74
72
static ::$ booted = true ;
75
73
76
- self ::$ kernelContainer = static ::$ kernel ->getContainer ();
77
-
78
74
return static ::$ kernel ;
79
75
}
80
76
@@ -93,7 +89,7 @@ protected static function getContainer(): ContainerInterface
93
89
}
94
90
95
91
try {
96
- return self ::$ kernelContainer ->get ('test.service_container ' );
92
+ return self ::$ kernel -> getContainer () ->get ('test.service_container ' );
97
93
} catch (ServiceNotFoundException $ e ) {
98
94
throw new \LogicException ('Could not find service "test.service_container". Try updating the "framework.test" config to "true". ' , 0 , $ e );
99
95
}
@@ -142,14 +138,9 @@ protected static function createKernel(array $options = []): KernelInterface
142
138
protected static function ensureKernelShutdown ()
143
139
{
144
140
if (null !== static ::$ kernel ) {
141
+ static ::$ kernel ->boot ();
145
142
static ::$ kernel ->shutdown ();
146
143
static ::$ booted = false ;
147
144
}
148
-
149
- if (self ::$ kernelContainer instanceof ResetInterface) {
150
- self ::$ kernelContainer ->reset ();
151
- }
152
-
153
- self ::$ kernelContainer = null ;
154
145
}
155
146
}
0 commit comments