@@ -16,6 +16,9 @@ class WpContextTest extends TestCase
1616{
1717 use MockeryPHPUnitIntegration;
1818
19+ /**
20+ * @var string
21+ */
1922 private $ currentPath = '/ ' ;
2023
2124 /**
@@ -25,7 +28,7 @@ protected function setUp(): void
2528 {
2629 parent ::setUp ();
2730 Monkey \setUp ();
28- Monkey \Functions \expect ('add_query_arg ' )->with ([])->andReturnUsing (function () {
31+ Monkey \Functions \expect ('add_query_arg ' )->with ([])->andReturnUsing (function (): string {
2932 return $ this ->currentPath ;
3033 });
3134 }
@@ -100,7 +103,6 @@ public function testIsLoginLate(): void
100103 $ this ->mockIsRestRequest (false );
101104 $ this ->mockIsLoginRequest (false );
102105
103- /** @var callable|null $onLoginInit */
104106 $ onLoginInit = null ;
105107 Monkey \Actions \expectAdded ('login_init ' )
106108 ->whenHappen (function (callable $ callback ) use (&$ onLoginInit ) {
@@ -111,6 +113,7 @@ public function testIsLoginLate(): void
111113
112114 static ::assertTrue ($ context ->isCore ());
113115 static ::assertFalse ($ context ->isLogin ());
116+ /** @var callable $onLoginInit */
114117 $ onLoginInit ();
115118 static ::assertTrue ($ context ->isLogin ());
116119 }
@@ -156,7 +159,6 @@ public function testIsRestLate(): void
156159 $ this ->mockIsRestRequest (false );
157160 $ this ->mockIsLoginRequest (false );
158161
159- /** @var callable|null $onRestInit */
160162 $ onRestInit = null ;
161163 Monkey \Actions \expectAdded ('rest_api_init ' )
162164 ->whenHappen (function (callable $ callback ) use (&$ onRestInit ) {
@@ -167,6 +169,7 @@ public function testIsRestLate(): void
167169
168170 static ::assertTrue ($ context ->isCore ());
169171 static ::assertFalse ($ context ->isRest ());
172+ /** @var callable $onRestInit */
170173 $ onRestInit ();
171174 static ::assertTrue ($ context ->isRest ());
172175 }
@@ -331,7 +334,7 @@ public function testJsonSerialize(): void
331334 $ this ->mockIsLoginRequest (true );
332335
333336 $ context = WpContext::determine ();
334- $ decoded = json_decode (json_encode ($ context ), true );
337+ $ decoded = ( array ) json_decode (( string ) json_encode ($ context ), true );
335338
336339 static ::assertTrue ($ decoded [WpContext::CORE ]);
337340 static ::assertTrue ($ decoded [WpContext::LOGIN ]);
@@ -348,8 +351,8 @@ public function testJsonSerialize(): void
348351 */
349352 private function mockIsRestRequest (bool $ is ): void
350353 {
351- Monkey \Functions \expect ('get_option ' )->with ('permalink_structure ' )->andReturn (false );
352- Monkey \ Functions \stubs ([ ' set_url_scheme ' ] );
354+ Monkey \Functions \expect ('get_option ' )->with ('permalink_structure ' )->andReturn (true );
355+ $ GLOBALS [ ' wp_rewrite ' ] = \Mockery:: mock ( ' WP_Rewrite ' );
353356 Monkey \Functions \when ('get_rest_url ' )->justReturn ('https://example.com/wp-json ' );
354357 $ is and $ this ->currentPath = '/wp-json/foo ' ;
355358 }
@@ -361,7 +364,7 @@ private function mockIsLoginRequest(bool $is): void
361364 {
362365 $ is and $ this ->currentPath = '/wp-login.php ' ;
363366 Monkey \Functions \when ('wp_login_url ' )->justReturn ('https://example.com/wp-login.php ' );
364- Monkey \Functions \when ('home_url ' )->alias (static function ($ path = '' ) {
367+ Monkey \Functions \when ('home_url ' )->alias (static function (string $ path = '' ): string {
365368 return 'https://example.com/ ' . ltrim ($ path , '/ ' );
366369 });
367370 }
0 commit comments