@@ -171,20 +171,36 @@ public function testMiddlewareCanBeEnabled(): void
171171 TestRequestMiddleware::reset ();
172172 }
173173
174- public function testWithMiddlewareOptionsPassesOptionsToMiddleware (): void
174+ public function testWithMiddlewareOptionsPassesOptionsToRequestMiddleware (): void
175175 {
176176 $ client = new ApiClient ();
177177 $ options = ['key ' => 'value ' , 'timeout ' => 30 ];
178178
179179 $ pending = $ client
180180 ->withMiddlewareOptions ($ options )
181- ->withRequestMiddleware ([OptionsCheckingMiddleware ::class]);
181+ ->withRequestMiddleware ([RequestOptionsCheckingMiddleware ::class]);
182182
183183 Http::fake (['test ' => Http::response ('{"success": true} ' )]);
184184 $ pending ->get ('test ' );
185185
186- $ this ->assertEquals ($ options , OptionsCheckingMiddleware::$ receivedOptions );
187- OptionsCheckingMiddleware::reset ();
186+ $ this ->assertEquals ($ options , RequestOptionsCheckingMiddleware::$ receivedOptions );
187+ RequestOptionsCheckingMiddleware::reset ();
188+ }
189+
190+ public function testWithMiddlewareOptionsPassesOptionsToResponseMiddleware (): void
191+ {
192+ $ client = new ApiClient ();
193+ $ options = ['key ' => 'value ' , 'timeout ' => 30 ];
194+
195+ $ pending = $ client
196+ ->withMiddlewareOptions ($ options )
197+ ->withResponseMiddleware ([ResponseOptionsCheckingMiddleware::class]);
198+
199+ Http::fake (['test ' => Http::response ('{"success": true} ' )]);
200+ $ pending ->get ('test ' );
201+
202+ $ this ->assertEquals ($ options , ResponseOptionsCheckingMiddleware::$ receivedOptions );
203+ ResponseOptionsCheckingMiddleware::reset ();
188204 }
189205
190206 public function testMiddlewareCaching (): void
@@ -462,7 +478,7 @@ public function handle(ApiRequest $request, callable $next): ApiRequest
462478 }
463479}
464480
465- class OptionsCheckingMiddleware
481+ class RequestOptionsCheckingMiddleware
466482{
467483 public static ?array $ receivedOptions = null ;
468484
@@ -482,6 +498,26 @@ public static function reset(): void
482498 }
483499}
484500
501+ class ResponseOptionsCheckingMiddleware
502+ {
503+ public static ?array $ receivedOptions = null ;
504+
505+ public function __construct (protected ?array $ config = null )
506+ {
507+ }
508+
509+ public function handle (ApiResponse $ response , callable $ next ): ApiResponse
510+ {
511+ self ::$ receivedOptions = $ response ->context ('options ' );
512+ return $ next ($ response );
513+ }
514+
515+ public static function reset (): void
516+ {
517+ self ::$ receivedOptions = null ;
518+ }
519+ }
520+
485521class CachingTestMiddleware
486522{
487523 public static ?string $ instanceId = null ;
0 commit comments