Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/HttpClientMock/MockRequestBuilderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
}

if (is_callable($body)) {
$mockRequestBuilder->content((string) $body());
$mockRequestBuilder->content((string) $body((int) $contentLength));

Check warning on line 135 in src/HttpClientMock/MockRequestBuilderFactory.php

View check run for this annotation

Codecov / codecov/patch

src/HttpClientMock/MockRequestBuilderFactory.php#L135

Added line #L135 was not covered by tests

return;
}
Expand Down
10 changes: 8 additions & 2 deletions tests/HttpClientMock/MockRequestBuilderFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\StreamInterface;

use function sprintf;

#[CoversClass(MockRequestBuilderFactory::class)]
final class MockRequestBuilderFactoryTest extends TestCase
{
Expand Down Expand Up @@ -52,13 +54,17 @@ public function testBuildsRequestWithJsonInBody(): void

public function testBuildsRequestWithCallableInBody(): void
{
$size = 1;
$body = $this->getMockBuilder(StreamInterface::class)->getMock();
$body->method('read')
$body
->expects(self::once())
->method('read')
->with($size)
->willReturn('{"foo": "bar"}');

$options = [
'headers' => [
'Content-Length: 1',
sprintf('Content-Length: %d', $size),
'Content-Type: application/json',
],
'body' => static fn (int $size) => $body->read($size),
Expand Down
Loading