@@ -114,7 +114,7 @@ public function getApplication(): \yii\base\Application
114
114
public function resetApplication (bool $ closeSession = true ): void
115
115
{
116
116
codecept_debug ('Destroying application ' );
117
- if (true === $ closeSession ) {
117
+ if ($ closeSession ) {
118
118
$ this ->closeSession ();
119
119
}
120
120
Yii::$ app = null ;
@@ -141,13 +141,13 @@ public function findAndLoginUser(int|string|IdentityInterface $user): void
141
141
throw new ConfigurationException ('The user component is not configured ' );
142
142
}
143
143
144
- if ($ user instanceof \ yii \ web \ IdentityInterface) {
144
+ if ($ user instanceof IdentityInterface) {
145
145
$ identity = $ user ;
146
146
} else {
147
147
// class name implementing IdentityInterface
148
148
$ identityClass = $ userComponent ->identityClass ;
149
- $ identity = call_user_func ([ $ identityClass, ' findIdentity ' ], $ user );
150
- if (! isset ( $ identity) ) {
149
+ $ identity = $ identityClass:: findIdentity ( $ user );
150
+ if ($ identity === null ) {
151
151
throw new \RuntimeException ('User not found ' );
152
152
}
153
153
}
@@ -233,7 +233,7 @@ private function getDomainRegex(string $template): string
233
233
'/<(?:\w+):?([^>]+)?>/u ' ,
234
234
function ($ matches ) use (&$ parameters ) {
235
235
$ key = '__ ' . count ($ parameters ) . '__ ' ;
236
- $ parameters [$ key ] = isset ( $ matches [1 ]) ? $ matches [ 1 ] : '\w+ ' ;
236
+ $ parameters [$ key ] = $ matches [1 ] ?? '\w+ ' ;
237
237
return $ key ;
238
238
},
239
239
$ template
@@ -258,15 +258,10 @@ public function startApp(?\yii\log\Logger $logger = null): void
258
258
codecept_debug ('Starting application ' );
259
259
$ config = require ($ this ->configFile );
260
260
if (!isset ($ config ['class ' ])) {
261
- if (null !== $ this ->applicationClass ) {
262
- $ config ['class ' ] = $ this ->applicationClass ;
263
- } else {
264
- $ config ['class ' ] = 'yii\web\Application ' ;
265
- }
261
+ $ config ['class ' ] = $ this ->applicationClass ?? 'yii\web\Application ' ;
266
262
}
267
263
268
- if (isset ($ config ['container ' ]))
269
- {
264
+ if (isset ($ config ['container ' ])) {
270
265
Yii::configure (Yii::$ container , $ config ['container ' ]);
271
266
unset($ config ['container ' ]);
272
267
}
@@ -326,9 +321,6 @@ public function doRequest(object $request): \Symfony\Component\BrowserKit\Respon
326
321
$ target ->enabled = false ;
327
322
}
328
323
329
-
330
-
331
-
332
324
$ yiiRequest = $ app ->getRequest ();
333
325
if ($ request ->getContent () !== null ) {
334
326
$ yiiRequest ->setRawBody ($ request ->getContent ());
@@ -441,7 +433,7 @@ protected function mockMailer(array $config): array
441
433
442
434
$ mailerConfig = [
443
435
'class ' => TestMailer::class,
444
- 'callback ' => function (MessageInterface $ message ) {
436
+ 'callback ' => function (MessageInterface $ message ): void {
445
437
$ this ->emails [] = $ message ;
446
438
}
447
439
];
@@ -474,7 +466,7 @@ public function getContext(): array
474
466
{
475
467
return [
476
468
'cookieJar ' => $ this ->cookieJar ,
477
- 'history ' => $ this ->history ,
469
+ 'history ' => $ this ->history ,
478
470
];
479
471
}
480
472
@@ -509,11 +501,12 @@ protected function resetResponse(Application $app): void
509
501
{
510
502
$ method = $ this ->responseCleanMethod ;
511
503
// First check the current response object.
512
- if (($ app ->response ->hasEventHandlers (\yii \web \Response::EVENT_BEFORE_SEND )
504
+ if (
505
+ ($ app ->response ->hasEventHandlers (\yii \web \Response::EVENT_BEFORE_SEND )
513
506
|| $ app ->response ->hasEventHandlers (\yii \web \Response::EVENT_AFTER_SEND )
514
507
|| $ app ->response ->hasEventHandlers (\yii \web \Response::EVENT_AFTER_PREPARE )
515
- || count ($ app ->response ->getBehaviors ()) > 0
516
- ) && $ method === self ::CLEAN_RECREATE
508
+ || count ($ app ->response ->getBehaviors ()) > 0 )
509
+ && $ method === self ::CLEAN_RECREATE
517
510
) {
518
511
Debug::debug (<<<TEXT
519
512
[WARNING] You are attaching event handlers or behaviors to the response object. But the Yii2 module is configured to recreate
@@ -525,17 +518,12 @@ protected function resetResponse(Application $app): void
525
518
$ method = self ::CLEAN_CLEAR ;
526
519
}
527
520
528
- switch ($ method ) {
529
- case self ::CLEAN_FORCE_RECREATE :
530
- case self ::CLEAN_RECREATE :
531
- $ app ->set ('response ' , $ app ->getComponents ()['response ' ]);
532
- break ;
533
- case self ::CLEAN_CLEAR :
534
- $ app ->response ->clear ();
535
- break ;
536
- case self ::CLEAN_MANUAL :
537
- break ;
538
- }
521
+ match ($ method ) {
522
+ self ::CLEAN_FORCE_RECREATE , self ::CLEAN_RECREATE => $ app ->set ('response ' , $ app ->getComponents ()['response ' ]),
523
+ self ::CLEAN_CLEAR => $ app ->response ->clear (),
524
+ self ::CLEAN_MANUAL => null ,
525
+ default => throw new \InvalidArgumentException ("Unknown method: $ method " ),
526
+ };
539
527
}
540
528
541
529
protected function resetRequest (Application $ app ): void
@@ -555,28 +543,24 @@ protected function resetRequest(Application $app): void
555
543
$ method = self ::CLEAN_CLEAR ;
556
544
}
557
545
558
- switch ($ method ) {
559
- case self ::CLEAN_FORCE_RECREATE :
560
- case self ::CLEAN_RECREATE :
561
- $ app ->set ('request ' , $ app ->getComponents ()['request ' ]);
562
- break ;
563
- case self ::CLEAN_CLEAR :
546
+ match ($ method ) {
547
+ self ::CLEAN_FORCE_RECREATE , self ::CLEAN_RECREATE => $ app ->set ('request ' , $ app ->getComponents ()['request ' ]),
548
+ self ::CLEAN_CLEAR => (function () use ($ request ): void {
564
549
$ request ->getHeaders ()->removeAll ();
565
550
$ request ->setBaseUrl (null );
566
551
$ request ->setHostInfo (null );
567
- $ request ->setPathInfo (null );
568
- $ request ->setScriptFile (null );
569
- $ request ->setScriptUrl (null );
570
- $ request ->setUrl (null );
552
+ $ request ->setPathInfo ('' );
553
+ $ request ->setScriptFile ('' );
554
+ $ request ->setScriptUrl ('' );
555
+ $ request ->setUrl ('' );
571
556
$ request ->setPort (0 );
572
557
$ request ->setSecurePort (0 );
573
- $ request ->setAcceptableContentTypes (null );
574
- $ request ->setAcceptableLanguages (null );
575
-
576
- break ;
577
- case self ::CLEAN_MANUAL :
578
- break ;
579
- }
558
+ $ request ->setAcceptableContentTypes ([]);
559
+ $ request ->setAcceptableLanguages ([]);
560
+ })(),
561
+ self ::CLEAN_MANUAL => null ,
562
+ default => throw new \InvalidArgumentException ("Unknown method: $ method " ),
563
+ };
580
564
}
581
565
582
566
/**
0 commit comments