Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0b4981a

Browse filesBrowse 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
Copy full SHA for 0b4981a

File tree

Expand file treeCollapse file tree

2 files changed

+17
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-1
lines changed

‎Response/JsonMockResponse.php

Copy file name to clipboardExpand all lines: Response/JsonMockResponse.php
+1-1Lines 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

Copy file name to clipboardExpand all lines: Tests/Response/JsonMockResponseTest.php
+16Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.