14
14
use Symfony \Component \HttpFoundation \Response ;
15
15
use Symfony \Component \HttpKernel \HttpKernelBrowser ;
16
16
use Symfony \Component \HttpKernel \Kernel ;
17
+ use Symfony \Contracts \Service \ResetInterface ;
17
18
use Symfony \Component \HttpKernel \Profiler \Profiler ;
18
19
use function array_keys ;
19
20
use function codecept_debug ;
@@ -31,7 +32,7 @@ public function __construct(
31
32
parent ::__construct ($ kernel );
32
33
$ this ->followRedirects ();
33
34
$ this ->container = $ this ->getContainer ();
34
- $ this ->rebootKernel (); // Ensure the profiler exists
35
+ $ this ->rebootKernel ();
35
36
}
36
37
37
38
/** @param Request $request */
@@ -47,7 +48,7 @@ protected function doRequest(object $request): Response
47
48
}
48
49
49
50
/**
50
- * Reboot kernel
51
+ * Reboots the kernel.
51
52
*
52
53
* Services from the list of persistent services
53
54
* are updated from service container before kernel shutdown
@@ -64,8 +65,7 @@ public function rebootKernel(): void
64
65
}
65
66
66
67
$ this ->persistDoctrineConnections ();
67
- $ this ->kernel ->boot ();
68
- $ this ->kernel ->shutdown ();
68
+ $ this ->ensureKernelShutdown ();
69
69
$ this ->kernel ->boot ();
70
70
$ this ->container = $ this ->getContainer ();
71
71
@@ -82,6 +82,22 @@ public function rebootKernel(): void
82
82
}
83
83
}
84
84
85
+ protected function ensureKernelShutdown (): void
86
+ {
87
+ $ this ->kernel ->boot ();
88
+ $ container = $ this ->kernel ->getContainer ();
89
+
90
+ if ($ container ->has ('services_resetter ' )) {
91
+ $ container ->get ('services_resetter ' );
92
+ }
93
+
94
+ $ this ->kernel ->shutdown ();
95
+
96
+ if ($ container instanceof ResetInterface) {
97
+ $ container ->reset ();
98
+ }
99
+ }
100
+
85
101
private function getContainer (): ?ContainerInterface
86
102
{
87
103
/** @var ContainerInterface $container */
@@ -120,12 +136,16 @@ private function persistDoctrineConnections(): void
120
136
}
121
137
122
138
$ reflectedContainer = new ReflectionClass ($ publicContainer );
123
- $ reflectionTarget = $ reflectedContainer ->hasProperty ('parameters ' ) ? $ publicContainer : $ publicContainer ->getParameterBag ();
139
+ $ reflectionTarget = $ reflectedContainer ->hasProperty ('parameters ' )
140
+ ? $ publicContainer
141
+ : $ publicContainer ->getParameterBag ();
124
142
125
143
$ reflectedParameters = new ReflectionProperty ($ reflectionTarget , 'parameters ' );
126
144
$ reflectedParameters ->setAccessible (true );
127
145
$ parameters = $ reflectedParameters ->getValue ($ reflectionTarget );
128
- unset($ parameters ['doctrine.connections ' ]);
146
+ if (array_key_exists ('doctrine.connections ' , $ parameters )) {
147
+ $ parameters ['doctrine.connections ' ] = [];
148
+ }
129
149
$ reflectedParameters ->setValue ($ reflectionTarget , $ parameters );
130
150
}
131
151
}
0 commit comments