Skip to content

Commit e52ff9e

Browse files
Jost Völkertemp
authored andcommitted
fix: pass size to content cb in MockRequestBuilder
1 parent 703d5e7 commit e52ff9e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/HttpClientMock/MockRequestBuilderFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private function processBody(
132132
}
133133

134134
if (is_callable($body)) {
135-
$mockRequestBuilder->content((string) $body());
135+
$mockRequestBuilder->content((string) $body((int) $contentLength));
136136

137137
return;
138138
}

tests/HttpClientMock/MockRequestBuilderFactoryTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use PHPUnit\Framework\TestCase;
1010
use Psr\Http\Message\StreamInterface;
1111

12+
use function sprintf;
13+
1214
#[CoversClass(MockRequestBuilderFactory::class)]
1315
final class MockRequestBuilderFactoryTest extends TestCase
1416
{
@@ -52,13 +54,17 @@ public function testBuildsRequestWithJsonInBody(): void
5254

5355
public function testBuildsRequestWithCallableInBody(): void
5456
{
57+
$size = 1;
5558
$body = $this->getMockBuilder(StreamInterface::class)->getMock();
56-
$body->method('read')
59+
$body
60+
->expects(self::once())
61+
->method('read')
62+
->with($size)
5763
->willReturn('{"foo": "bar"}');
5864

5965
$options = [
6066
'headers' => [
61-
'Content-Length: 1',
67+
sprintf('Content-Length: %d', $size),
6268
'Content-Type: application/json',
6369
],
6470
'body' => static fn (int $size) => $body->read($size),

0 commit comments

Comments
 (0)