From c1460f8bc6075c9ef97f8174944ef16ee86bc7da Mon Sep 17 00:00:00 2001 From: Deleu Date: Tue, 20 Apr 2021 01:18:02 +0200 Subject: [PATCH 1/2] Send pending body with the request --- src/Illuminate/Http/Client/PendingRequest.php | 2 ++ tests/Http/HttpClientTest.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Illuminate/Http/Client/PendingRequest.php b/src/Illuminate/Http/Client/PendingRequest.php index f0790c5a54a3..f7723243e917 100644 --- a/src/Illuminate/Http/Client/PendingRequest.php +++ b/src/Illuminate/Http/Client/PendingRequest.php @@ -642,6 +642,8 @@ public function send(string $method, string $url, array $options = []) $options[$this->bodyFormat], $this->pendingFiles ); } + } else { + $options[$this->bodyFormat] = $this->pendingBody; } [$this->pendingBody, $this->pendingFiles] = [null, []]; diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index 84709fa3ba66..17572b0776b6 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -76,6 +76,21 @@ public function testResponseCanBeReturnedAsCollection() $this->assertEquals(collect(), $response->collect('missing_key')); } + public function testSendRequestBody() + { + $body = '{"test":"phpunit"}'; + + $fakeRequest = function(Request $request) use ($body) { + self::assertSame($body, $request->body()); + + return ['my' => 'response']; + }; + + $this->factory->fake($fakeRequest); + + $this->factory->withBody($body, 'application/json')->send('get', 'http://foo.com/api'); + } + public function testUrlsCanBeStubbedByPath() { $this->factory->fake([ From dc1e2762adde5514dde05930c1521c8833524a77 Mon Sep 17 00:00:00 2001 From: Deleu Date: Tue, 20 Apr 2021 01:22:13 +0200 Subject: [PATCH 2/2] StyleCI --- tests/Http/HttpClientTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index 17572b0776b6..a6637134708a 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -80,7 +80,7 @@ public function testSendRequestBody() { $body = '{"test":"phpunit"}'; - $fakeRequest = function(Request $request) use ($body) { + $fakeRequest = function (Request $request) use ($body) { self::assertSame($body, $request->body()); return ['my' => 'response'];