77use Closure ;
88use Codeception \Lib \Connector \Laravel \ExceptionHandlerDecorator as LaravelExceptionHandlerDecorator ;
99use Codeception \Lib \Connector \Laravel6 \ExceptionHandlerDecorator as Laravel6ExceptionHandlerDecorator ;
10+ use Codeception \Module \Laravel as LaravelModule ;
1011use Codeception \Stub ;
1112use Exception ;
1213use Illuminate \Contracts \Config \Repository as Config ;
2728
2829class Laravel extends Client
2930{
30- /**
31- * @var array
32- */
33- private $ bindings = [];
31+ private array $ bindings = [];
3432
35- /**
36- * @var array
37- */
38- private $ contextualBindings = [];
33+ private array $ contextualBindings = [];
3934
4035 /**
4136 * @var object[]
4237 */
43- private $ instances = [];
38+ private array $ instances = [];
4439
4540 /**
4641 * @var callable[]
4742 */
48- private $ applicationHandlers = [];
43+ private array $ applicationHandlers = [];
4944
50- /**
51- * @var Application
52- */
53- private $ app ;
45+ private ?AppContract $ app = null ;
5446
55- /**
56- * @var \Codeception\Module\Laravel
57- */
58- private $ module ;
47+ private LaravelModule $ module ;
5948
60- /**
61- * @var bool
62- */
63- private $ firstRequest = true ;
49+ private bool $ firstRequest = true ;
6450
65- /**
66- * @var array
67- */
68- private $ triggeredEvents = [];
51+ private array $ triggeredEvents = [];
6952
70- /**
71- * @var bool
72- */
73- private $ exceptionHandlingDisabled ;
53+ private bool $ exceptionHandlingDisabled ;
7454
75- /**
76- * @var bool
77- */
78- private $ middlewareDisabled ;
55+ private bool $ middlewareDisabled ;
7956
80- /**
81- * @var bool
82- */
83- private $ eventsDisabled ;
57+ private bool $ eventsDisabled ;
8458
85- /**
86- * @var bool
87- */
88- private $ modelEventsDisabled ;
59+ private bool $ modelEventsDisabled ;
8960
90- /**
91- * @var object
92- */
93- private $ oldDb ;
61+ private ?object $ oldDb = null ;
9462
9563 /**
9664 * Constructor.
9765 *
98- * @param \Codeception\Module\Laravel $module
66+ * @param LaravelModule $module
9967 * @throws Exception
10068 */
10169 public function __construct ($ module )
@@ -113,6 +81,7 @@ public function __construct($module)
11381 if (array_key_exists ('url ' , $ this ->module ->config )) {
11482 $ components = parse_url ($ this ->module ->config ['url ' ]);
11583 }
84+
11685 $ host = $ components ['host ' ] ?? 'localhost ' ;
11786
11887 parent ::__construct ($ this ->app , ['HTTP_HOST ' => $ host ]);
@@ -132,6 +101,7 @@ protected function doRequest($request): Response
132101 if (!$ this ->firstRequest ) {
133102 $ this ->initialize ($ request );
134103 }
104+
135105 $ this ->firstRequest = false ;
136106
137107 $ this ->applyBindings ();
@@ -157,27 +127,27 @@ private function initialize(SymfonyRequest $request = null): void
157127 $ this ->oldDb = $ db ;
158128 }
159129
160- $ this ->app = $ this ->kernel = $ this ->loadApplication ();
130+ $ this ->app = $ this ->loadApplication ();
131+ $ this ->kernel = $ this ->app ;
161132
162133 // Set the request instance for the application,
163134 if (is_null ($ request )) {
164135 $ appConfig = require $ this ->module ->config ['project_dir ' ] . 'config/app.php ' ;
165136 $ request = SymfonyRequest::create ($ appConfig ['url ' ]);
166137 }
138+
167139 $ this ->app ->instance ('request ' , Request::createFromBase ($ request ));
168140
169141 // Reset the old database after all the service providers are registered.
170142 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 );
175145 });
176146 }
177147
178148 $ this ->getHttpKernel ()->bootstrap ();
179149
180- $ listener = function ($ event ) {
150+ $ listener = function ($ event ): void {
181151 $ this ->triggeredEvents [] = $ this ->normalizeEvent ($ event );
182152 };
183153
@@ -230,7 +200,7 @@ private function mockEventDispatcher(): void
230200 // Even if events are disabled we still want to record the triggered events.
231201 // But by mocking the event dispatcher the wildcard listener registered in the initialize method is removed.
232202 // 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 {
234204 $ this ->triggeredEvents [] = $ this ->normalizeEvent ($ event );
235205
236206 return [];
@@ -253,7 +223,7 @@ private function normalizeEvent($event): string
253223 $ event = get_class ($ event );
254224 }
255225
256- if (preg_match ('/ ^bootstrapp(ing|ed): / ' , $ event )) {
226+ if (preg_match ('# ^bootstrapp(ing|ed): # ' , $ event )) {
257227 return $ event ;
258228 }
259229
0 commit comments