Skip to content

Commit 0cef5f3

Browse files
mmokhinicolas-grekas
authored andcommitted
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. In order not missing the type assertion point that `AssertSame` does, we also perform `assertInternalType('string'...` Sponsored-by: Platform.sh
1 parent bb9a67d commit 0cef5f3

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)