21
21
class Symfony extends HttpKernelBrowser
22
22
{
23
23
private bool $ hasPerformedRequest = false ;
24
-
25
24
private ?ContainerInterface $ container ;
26
25
27
- /**
28
- * Constructor.
29
- *
30
- * @param Kernel $kernel A booted HttpKernel instance
31
- * @param array $persistentServices An injected services
32
- */
33
26
public function __construct (
34
27
Kernel $ kernel ,
35
28
public array $ persistentServices = [],
@@ -74,14 +67,12 @@ public function rebootKernel(): void
74
67
75
68
$ this ->persistDoctrineConnections ();
76
69
$ this ->kernel ->reboot (null );
77
-
78
70
$ this ->container = $ this ->getContainer ();
79
71
80
72
foreach ($ this ->persistentServices as $ serviceName => $ service ) {
81
73
try {
82
74
$ this ->container ->set ($ serviceName , $ service );
83
75
} catch (InvalidArgumentException $ e ) {
84
- //Private services can't be set in Symfony 4
85
76
codecept_debug ("[Symfony] Can't set persistent service {$ serviceName }: " . $ e ->getMessage ());
86
77
}
87
78
}
@@ -95,31 +86,23 @@ private function getContainer(): ?ContainerInterface
95
86
{
96
87
/** @var ContainerInterface $container */
97
88
$ container = $ this ->kernel ->getContainer ();
98
- if ($ container ->has ('test.service_container ' )) {
99
- $ container = $ container ->get ('test.service_container ' );
100
- }
101
-
102
- return $ container ;
89
+ return $ container ->has ('test.service_container ' )
90
+ ? $ container ->get ('test.service_container ' )
91
+ : $ container ;
103
92
}
104
93
105
94
private function getProfiler (): ?Profiler
106
95
{
107
- if ($ this ->container ->has ('profiler ' )) {
108
- /** @var Profiler $profiler */
109
- $ profiler = $ this ->container ->get ('profiler ' );
110
- return $ profiler ;
111
- }
112
-
113
- return null ;
96
+ return $ this ->container ->has ('profiler ' )
97
+ ? $ this ->container ->get ('profiler ' )
98
+ : null ;
114
99
}
115
100
116
101
private function getService (string $ serviceName ): ?object
117
102
{
118
- if ($ this ->container ->has ($ serviceName )) {
119
- return $ this ->container ->get ($ serviceName );
120
- }
121
-
122
- return null ;
103
+ return $ this ->container ->has ($ serviceName )
104
+ ? $ this ->container ->get ($ serviceName )
105
+ : null ;
123
106
}
124
107
125
108
private function persistDoctrineConnections (): void
0 commit comments