3232use yii \web \Response as YiiResponse ;
3333use yii \web \User ;
3434
35-
3635/**
3736 * @extends Client<BrowserkitRequest, Response>
3837 */
3938class Yii2 extends Client
4039{
4140 use Shared \PhpSuperGlobalsConverter;
4241
43- const CLEAN_METHODS = [
42+ public const CLEAN_METHODS = [
4443 self ::CLEAN_RECREATE ,
4544 self ::CLEAN_CLEAR ,
4645 self ::CLEAN_FORCE_RECREATE ,
47- self ::CLEAN_MANUAL
46+ self ::CLEAN_MANUAL ,
4847 ];
4948 /**
5049 * Clean the response object by recreating it.
5150 * This might lose behaviors / event handlers / other changes that are done in the application bootstrap phase.
5251 */
53- const CLEAN_RECREATE = 'recreate ' ;
52+ public const CLEAN_RECREATE = 'recreate ' ;
5453 /**
5554 * Same as recreate but will not warn when behaviors / event handlers are lost.
5655 */
57- const CLEAN_FORCE_RECREATE = 'force_recreate ' ;
56+ public const CLEAN_FORCE_RECREATE = 'force_recreate ' ;
5857 /**
5958 * Clean the response object by resetting specific properties via its' `clear()` method.
6059 * This will keep behaviors / event handlers, but could inadvertently leave some changes intact.
6160 * @see \yii\web\Response::clear()
6261 */
63- const CLEAN_CLEAR = 'clear ' ;
62+ public const CLEAN_CLEAR = 'clear ' ;
6463
6564 /**
6665 * Do not clean the response, instead the test writer will be responsible for manually resetting the response in
6766 * between requests during one test
6867 */
69- const CLEAN_MANUAL = 'manual ' ;
68+ public const CLEAN_MANUAL = 'manual ' ;
7069
7170
7271 /**
@@ -257,7 +256,7 @@ function ($matches) use (&$parameters): string {
257256 $ parameters [$ key ] = $ matches [1 ] ?? '\w+ ' ;
258257 return $ key ;
259258 },
260- $ template
259+ $ template,
261260 );
262261 }
263262 if ($ template === null ) {
@@ -327,7 +326,7 @@ public function doRequest(object $request): Response
327326 $ queryString = parse_url ($ uri , PHP_URL_QUERY );
328327 $ _SERVER ['REQUEST_URI ' ] = $ queryString === null ? $ pathString : $ pathString . '? ' . $ queryString ;
329328 $ _SERVER ['REQUEST_METHOD ' ] = strtoupper ($ request ->getMethod ());
330- $ _SERVER ['QUERY_STRING ' ] = (string )$ queryString ;
329+ $ _SERVER ['QUERY_STRING ' ] = (string ) $ queryString ;
331330
332331 parse_str ($ queryString ?: '' , $ params );
333332 foreach ($ params as $ k => $ v ) {
@@ -403,7 +402,7 @@ public function doRequest(object $request): Response
403402 protected function encodeCookies (
404403 YiiResponse $ response ,
405404 YiiRequest $ request ,
406- Security $ security
405+ Security $ security,
407406 ): void {
408407 if ($ request ->enableCookieValidation ) {
409408 $ validationKey = $ request ->cookieValidationKey ;
@@ -419,15 +418,15 @@ protected function encodeCookies(
419418 : $ cookie ->value ;
420419 $ value = $ security ->hashData (serialize ($ data ), $ validationKey );
421420 }
422- $ expires = is_int ($ cookie ->expire ) ? (string )$ cookie ->expire : null ;
421+ $ expires = is_int ($ cookie ->expire ) ? (string ) $ cookie ->expire : null ;
423422 $ c = new Cookie (
424423 $ cookie ->name ,
425424 $ value ,
426425 $ expires ,
427426 $ cookie ->path ,
428427 $ cookie ->domain ,
429428 $ cookie ->secure ,
430- $ cookie ->httpOnly
429+ $ cookie ->httpOnly ,
431430 );
432431 $ this ->getCookieJar ()->set ($ c );
433432 }
@@ -457,13 +456,15 @@ protected function mockMailer(array $config): array
457456 'class ' => TestMailer::class,
458457 'callback ' => function (BaseMessage $ message ): void {
459458 $ this ->emails [] = $ message ;
460- }
459+ },
461460 ];
462461
463462 if (isset ($ config ['components ' ])) {
464463 if (!is_array ($ config ['components ' ])) {
465- throw new ModuleConfigException ($ this ,
466- "Yii2 config does not contain components key is not of type array " );
464+ throw new ModuleConfigException (
465+ $ this ,
466+ "Yii2 config does not contain components key is not of type array " ,
467+ );
467468 }
468469 } else {
469470 $ config ['components ' ] = [];
@@ -538,12 +539,13 @@ protected function resetResponse(Application $app): void
538539 || count ($ app ->response ->getBehaviors ()) > 0 )
539540 && $ method === self ::CLEAN_RECREATE
540541 ) {
541- Debug::debug (<<<TEXT
542+ Debug::debug (
543+ <<<TEXT
542544[WARNING] You are attaching event handlers or behaviors to the response object. But the Yii2 module is configured to recreate
543545the response object, this means any behaviors or events that are not attached in the component config will be lost.
544546We will fall back to clearing the response. If you are certain you want to recreate it, please configure
545547responseCleanMethod = 'force_recreate' in the module.
546- TEXT
548+ TEXT ,
547549 );
548550 $ method = self ::CLEAN_CLEAR ;
549551 }
@@ -563,12 +565,13 @@ protected function resetRequest(Application $app): void
563565
564566 // First check the current request object.
565567 if (count ($ request ->getBehaviors ()) > 0 && $ method === self ::CLEAN_RECREATE ) {
566- Debug::debug (<<<TEXT
568+ Debug::debug (
569+ <<<TEXT
567570[WARNING] You are attaching event handlers or behaviors to the request object. But the Yii2 module is configured to recreate
568571the request object, this means any behaviors or events that are not attached in the component config will be lost.
569572We will fall back to clearing the request. If you are certain you want to recreate it, please configure
570573requestCleanMethod = 'force_recreate' in the module.
571- TEXT
574+ TEXT ,
572575 );
573576 $ method = self ::CLEAN_CLEAR ;
574577 }
0 commit comments