7
7
use Closure ;
8
8
use Codeception \Lib \Connector \Laravel \ExceptionHandlerDecorator as LaravelExceptionHandlerDecorator ;
9
9
use Codeception \Lib \Connector \Laravel6 \ExceptionHandlerDecorator as Laravel6ExceptionHandlerDecorator ;
10
+ use Codeception \Module \Laravel as LaravelModule ;
10
11
use Codeception \Stub ;
11
12
use Exception ;
12
13
use Illuminate \Contracts \Config \Repository as Config ;
27
28
28
29
class Laravel extends Client
29
30
{
30
- /**
31
- * @var array
32
- */
33
- private $ bindings = [];
31
+ private array $ bindings = [];
34
32
35
- /**
36
- * @var array
37
- */
38
- private $ contextualBindings = [];
33
+ private array $ contextualBindings = [];
39
34
40
35
/**
41
36
* @var object[]
42
37
*/
43
- private $ instances = [];
38
+ private array $ instances = [];
44
39
45
40
/**
46
41
* @var callable[]
47
42
*/
48
- private $ applicationHandlers = [];
43
+ private array $ applicationHandlers = [];
49
44
50
- /**
51
- * @var Application
52
- */
53
- private $ app ;
45
+ private ?AppContract $ app = null ;
54
46
55
- /**
56
- * @var \Codeception\Module\Laravel
57
- */
58
- private $ module ;
47
+ private LaravelModule $ module ;
59
48
60
- /**
61
- * @var bool
62
- */
63
- private $ firstRequest = true ;
49
+ private bool $ firstRequest = true ;
64
50
65
- /**
66
- * @var array
67
- */
68
- private $ triggeredEvents = [];
51
+ private array $ triggeredEvents = [];
69
52
70
- /**
71
- * @var bool
72
- */
73
- private $ exceptionHandlingDisabled ;
53
+ private bool $ exceptionHandlingDisabled ;
74
54
75
- /**
76
- * @var bool
77
- */
78
- private $ middlewareDisabled ;
55
+ private bool $ middlewareDisabled ;
79
56
80
- /**
81
- * @var bool
82
- */
83
- private $ eventsDisabled ;
57
+ private bool $ eventsDisabled ;
84
58
85
- /**
86
- * @var bool
87
- */
88
- private $ modelEventsDisabled ;
59
+ private bool $ modelEventsDisabled ;
89
60
90
- /**
91
- * @var object
92
- */
93
- private $ oldDb ;
61
+ private ?object $ oldDb = null ;
94
62
95
63
/**
96
64
* Constructor.
97
65
*
98
- * @param \Codeception\Module\Laravel $module
66
+ * @param LaravelModule $module
99
67
* @throws Exception
100
68
*/
101
69
public function __construct ($ module )
@@ -113,6 +81,7 @@ public function __construct($module)
113
81
if (array_key_exists ('url ' , $ this ->module ->config )) {
114
82
$ components = parse_url ($ this ->module ->config ['url ' ]);
115
83
}
84
+
116
85
$ host = $ components ['host ' ] ?? 'localhost ' ;
117
86
118
87
parent ::__construct ($ this ->app , ['HTTP_HOST ' => $ host ]);
@@ -132,6 +101,7 @@ protected function doRequest($request): Response
132
101
if (!$ this ->firstRequest ) {
133
102
$ this ->initialize ($ request );
134
103
}
104
+
135
105
$ this ->firstRequest = false ;
136
106
137
107
$ this ->applyBindings ();
@@ -157,27 +127,27 @@ private function initialize(SymfonyRequest $request = null): void
157
127
$ this ->oldDb = $ db ;
158
128
}
159
129
160
- $ this ->app = $ this ->kernel = $ this ->loadApplication ();
130
+ $ this ->app = $ this ->loadApplication ();
131
+ $ this ->kernel = $ this ->app ;
161
132
162
133
// Set the request instance for the application,
163
134
if (is_null ($ request )) {
164
135
$ appConfig = require $ this ->module ->config ['project_dir ' ] . 'config/app.php ' ;
165
136
$ request = SymfonyRequest::create ($ appConfig ['url ' ]);
166
137
}
138
+
167
139
$ this ->app ->instance ('request ' , Request::createFromBase ($ request ));
168
140
169
141
// Reset the old database after all the service providers are registered.
170
142
if ($ this ->oldDb ) {
171
- $ this ->getEvents ()->listen ('bootstrapped: ' . RegisterProviders::class, function () {
172
- $ this ->app ->singleton ('db ' , function () {
173
- return $ this ->oldDb ;
174
- });
143
+ $ this ->getEvents ()->listen ('bootstrapped: ' . RegisterProviders::class, function (): void {
144
+ $ this ->app ->singleton ('db ' , fn (): object => $ this ->oldDb );
175
145
});
176
146
}
177
147
178
148
$ this ->getHttpKernel ()->bootstrap ();
179
149
180
- $ listener = function ($ event ) {
150
+ $ listener = function ($ event ): void {
181
151
$ this ->triggeredEvents [] = $ this ->normalizeEvent ($ event );
182
152
};
183
153
@@ -230,7 +200,7 @@ private function mockEventDispatcher(): void
230
200
// Even if events are disabled we still want to record the triggered events.
231
201
// But by mocking the event dispatcher the wildcard listener registered in the initialize method is removed.
232
202
// So to record the triggered events we have to catch the calls to the fire method of the event dispatcher mock.
233
- $ callback = function ($ event ) {
203
+ $ callback = function ($ event ): array {
234
204
$ this ->triggeredEvents [] = $ this ->normalizeEvent ($ event );
235
205
236
206
return [];
@@ -253,7 +223,7 @@ private function normalizeEvent($event): string
253
223
$ event = get_class ($ event );
254
224
}
255
225
256
- if (preg_match ('/ ^bootstrapp(ing|ed): / ' , $ event )) {
226
+ if (preg_match ('# ^bootstrapp(ing|ed): # ' , $ event )) {
257
227
return $ event ;
258
228
}
259
229
0 commit comments