Skip to content

Commit 57c283c

Browse files
authored
[8.x] Fix Http::withBody() not being sent (#37057)
* Send pending body with the request * StyleCI
1 parent 856cdba commit 57c283c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Illuminate/Http/Client/PendingRequest.php

+2
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,8 @@ public function send(string $method, string $url, array $options = [])
642642
$options[$this->bodyFormat], $this->pendingFiles
643643
);
644644
}
645+
} else {
646+
$options[$this->bodyFormat] = $this->pendingBody;
645647
}
646648

647649
[$this->pendingBody, $this->pendingFiles] = [null, []];

tests/Http/HttpClientTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ public function testResponseCanBeReturnedAsCollection()
7676
$this->assertEquals(collect(), $response->collect('missing_key'));
7777
}
7878

79+
public function testSendRequestBody()
80+
{
81+
$body = '{"test":"phpunit"}';
82+
83+
$fakeRequest = function (Request $request) use ($body) {
84+
self::assertSame($body, $request->body());
85+
86+
return ['my' => 'response'];
87+
};
88+
89+
$this->factory->fake($fakeRequest);
90+
91+
$this->factory->withBody($body, 'application/json')->send('get', 'http://foo.com/api');
92+
}
93+
7994
public function testUrlsCanBeStubbedByPath()
8095
{
8196
$this->factory->fake([

0 commit comments

Comments
 (0)