Skip to content

Commit

Permalink
[8.x] Fix Http::withBody() not being sent (#37057)
Browse files Browse the repository at this point in the history
* Send pending body with the request

* StyleCI
  • Loading branch information
deleugpn committed Apr 20, 2021
1 parent 856cdba commit 57c283c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Illuminate/Http/Client/PendingRequest.php
Expand Up @@ -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, []];
Expand Down
15 changes: 15 additions & 0 deletions tests/Http/HttpClientTest.php
Expand Up @@ -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([
Expand Down

0 comments on commit 57c283c

Please sign in to comment.