Skip to content

Commit e5059a0

Browse files
minor symfony#27637 Set serialize_precision explicitly to avoid fancy float rounding (Majkl578)
This PR was merged into the 2.8 branch. Discussion ---------- Set serialize_precision explicitly to avoid fancy float rounding | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | - This is fixing some of the test failures I was seeing locally due to increased `serialize_precision` INI setting: ``` 2) Symfony\Component\HttpFoundation\Tests\JsonResponseTest::testConstructorWithSimpleTypes Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -'0.1' +'0.10000000000000001' /www/symfony/symfony/src/Symfony/Component/HttpFoundation/Tests/JsonResponseTest.php:46 3) Symfony\Component\HttpFoundation\Tests\JsonResponseTest::testStaticCreateWithSimpleTypes Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -'0.1' +'0.10000000000000001' ``` The test assertions should not depend on externally configured PHP configuration. Also default value for this option was changed multiple times: http://php.net/manual/en/ini.core.php#ini.serialize-precision For compatibility reasons (with PHP <7.x) `-1` can't be used. https://3v4l.org/HBNsT HHVM doesn't seem to support this though, how to handle this? Commits ------- b5ee7c3 Set serialize_precision explicitly to avoid fancy float rounding
2 parents 0f2b752 + b5ee7c3 commit e5059a0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/Symfony/Component/HttpFoundation/Tests/JsonResponseTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616

1717
class JsonResponseTest extends TestCase
1818
{
19+
protected function setUp()
20+
{
21+
parent::setUp();
22+
23+
if (!defined('HHVM_VERSION')) {
24+
$this->iniSet('serialize_precision', 14);
25+
}
26+
}
27+
1928
public function testConstructorEmptyCreatesJsonObject()
2029
{
2130
$response = new JsonResponse();

0 commit comments

Comments
 (0)