Skip to content

Commit a26c6d3

Browse files
minor symfony#31612 Use AsserEquals for floating-point values (mmokhi)
This PR was submitted for the master branch but it was merged into the 3.4 branch instead (closes symfony#31612). Discussion ---------- Use AsserEquals for floating-point values Use AssertEquals for these two specific case will do a better job, since it'll convert both '0.1' and result of `getContent()` into PHP's internal representation of floating-point and compares them and it should be fine. Using `AssertSame` for this tests brings floating-point serialization into consideration which of course will be php.ini specific. Sponsored-by: Platform.sh | Q | A | ------------- | --- | Branch? | master for features / 3.4, 4.2 or 4.3 for bug fixes <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/roadmap): - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. --> Commits ------- 0cef5f3 Use AsserEquals for floating-point values
2 parents bb9a67d + 0cef5f3 commit a26c6d3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public function testConstructorWithSimpleTypes()
5252
$this->assertSame('0', $response->getContent());
5353

5454
$response = new JsonResponse(0.1);
55-
$this->assertSame('0.1', $response->getContent());
55+
$this->assertEquals('0.1', $response->getContent());
56+
$this->assertInternalType('string', $response->getContent());
5657

5758
$response = new JsonResponse(true);
5859
$this->assertSame('true', $response->getContent());
@@ -140,7 +141,8 @@ public function testStaticCreateWithSimpleTypes()
140141

141142
$response = JsonResponse::create(0.1);
142143
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
143-
$this->assertSame('0.1', $response->getContent());
144+
$this->assertEquals('0.1', $response->getContent());
145+
$this->assertInternalType('string', $response->getContent());
144146

145147
$response = JsonResponse::create(true);
146148
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);

0 commit comments

Comments
 (0)