File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
src/Illuminate/Http/Client Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -1155,12 +1155,12 @@ public function pushHandlers($handlerStack)
11551155 {
11561156 return tap ($ handlerStack , function ($ stack ) {
11571157 $ stack ->push ($ this ->buildBeforeSendingHandler ());
1158- $ stack ->push ($ this ->buildRecorderHandler ());
11591158
11601159 $ this ->middleware ->each (function ($ middleware ) use ($ stack ) {
11611160 $ stack ->push ($ middleware );
11621161 });
11631162
1163+ $ stack ->push ($ this ->buildRecorderHandler ());
11641164 $ stack ->push ($ this ->buildStubHandler ());
11651165 });
11661166 }
Original file line number Diff line number Diff line change 2929use OutOfBoundsException ;
3030use PHPUnit \Framework \AssertionFailedError ;
3131use PHPUnit \Framework \TestCase ;
32+ use Psr \Http \Message \RequestInterface ;
3233use Psr \Http \Message \ResponseInterface ;
3334use RuntimeException ;
3435use Symfony \Component \VarDumper \VarDumper ;
@@ -1760,6 +1761,27 @@ public function testMiddlewareRunsWhenFaked()
17601761 $ this ->assertSame (['hyped-for ' => 'laravel-movie ' ], json_decode (tap ($ history [0 ]['request ' ]->getBody ())->rewind ()->getContents (), true ));
17611762 }
17621763
1764+ public function testMiddlewareRunsAndCanChangeRequestOnAssertSent ()
1765+ {
1766+ $ this ->factory ->fake (function (Request $ request ) {
1767+ return $ this ->factory ->response ('Fake ' );
1768+ });
1769+
1770+
1771+ $ pendingRequest = $ this ->factory ->withMiddleware (
1772+ Middleware::mapRequest (fn (RequestInterface $ request ) => $ request ->withHeader ('X-Test-Header ' , 'Test ' ))
1773+ );
1774+
1775+ $ pendingRequest ->post ('https://laravel.example ' , ['laravel ' => 'framework ' ]);
1776+
1777+ $ this ->factory ->assertSent (function (Request $ request ) {
1778+ return
1779+ $ request ->url () === 'https://laravel.example ' &&
1780+ $ request ->hasHeader ('X-Test-Header ' , 'Test ' );
1781+ });
1782+
1783+ }
1784+
17631785 public function testRequestExceptionIsNotThrownIfThePendingRequestIsSetToThrowOnFailureButTheResponseIsSuccessful ()
17641786 {
17651787 $ this ->factory ->fake ([
You can’t perform that action at this time.
0 commit comments