8000 Merge branch '6.4' into 7.0 · symfony/http-client@0b4981a · GitHub
[go: up one dir, main page]

Skip to content

Commit 0b4981a

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: Bump Symfony version to 6.4.6 Update VERSION for 6.4.5 Update CHANGELOG for 6.4.5 Bump Symfony version to 5.4.38 Update VERSION for 5.4.37 Update CONTRIBUTORS for 5.4.37 Update CHANGELOG for 5.4.37 [HttpClient] Preserve float in JsonMockResponse
2 parents 425f462 + 0215154 commit 0b4981a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Response/JsonMockResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class JsonMockResponse extends MockResponse
2121
public function __construct(mixed $body = [], array $info = [])
2222
{
2323
try {
24-
$json = json_encode($body, \JSON_THROW_ON_ERROR);
24+
$json = json_encode($body, \JSON_THROW_ON_ERROR | \JSON_PRESERVE_ZERO_FRACTION);
2525
} catch (\JsonException $e) {
2626
throw new InvalidArgumentException('JSON encoding failed: '.$e->getMessage(), $e->getCode(), $e);
2727
}

Tests/Response/JsonMockResponseTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ public function testJsonEncodeString()
5959
$this->assertSame('application/json', $response->getHeaders()['content-type'][0]);
6060
}
6161

62+
public function testJsonEncodeFloat()
63+
{
64+
$client = new MockHttpClient(new JsonMockResponse([
65+
'foo' => 1.23,
66+
'ccc' => 1.0,
67+
'baz' => 10.,
68+
]));
69+
$response = $client->request('GET', 'https://symfony.com');
70+
71+
$this->assertSame([
72+
'foo' => 1.23,
73+
'ccc' => 1.,
74+
'baz' => 10.,
75+
], $response->toArray());
76+
}
77+
6278
/**
6379
* @dataProvider responseHeadersProvider
6480
*/

0 commit comments

Comments
 (0)
0