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)
1155
1155
{
1156
1156
return tap ($ handlerStack , function ($ stack ) {
1157
1157
$ stack ->push ($ this ->buildBeforeSendingHandler ());
1158
- $ stack ->push ($ this ->buildRecorderHandler ());
1159
1158
1160
1159
$ this ->middleware ->each (function ($ middleware ) use ($ stack ) {
1161
1160
$ stack ->push ($ middleware );
1162
1161
});
1163
1162
1163
+ $ stack ->push ($ this ->buildRecorderHandler ());
1164
1164
$ stack ->push ($ this ->buildStubHandler ());
1165
1165
});
1166
1166
}
Original file line number Diff line number Diff line change 29
29
use OutOfBoundsException ;
30
30
use PHPUnit \Framework \AssertionFailedError ;
31
31
use PHPUnit \Framework \TestCase ;
32
+ use Psr \Http \Message \RequestInterface ;
32
33
use Psr \Http \Message \ResponseInterface ;
33
34
use RuntimeException ;
34
35
use Symfony \Component \VarDumper \VarDumper ;
@@ -1760,6 +1761,27 @@ public function testMiddlewareRunsWhenFaked()
1760
1761
$ this ->assertSame (['hyped-for ' => 'laravel-movie ' ], json_decode (tap ($ history [0 ]['request ' ]->getBody ())->rewind ()->getContents (), true ));
1761
1762
}
1762
1763
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
+
1763
1785
public function testRequestExceptionIsNotThrownIfThePendingRequestIsSetToThrowOnFailureButTheResponseIsSuccessful ()
1764
1786
{
1765
1787
$ this ->factory ->fake ([
You can’t perform that action at this time.
0 commit comments