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
This commit is contained in:
mmokhi 2019-05-24 19:14:44 +02:00 committed by Nicolas Grekas
parent bb9a67df3b
commit 0cef5f3ec9

View File

@ -52,7 +52,8 @@ class JsonResponseTest extends TestCase
$this->assertSame('0', $response->getContent());
$response = new JsonResponse(0.1);
$this->assertSame('0.1', $response->getContent());
$this->assertEquals('0.1', $response->getContent());
$this->assertInternalType('string', $response->getContent());
$response = new JsonResponse(true);
$this->assertSame('true', $response->getContent());
@ -140,7 +141,8 @@ class JsonResponseTest extends TestCase
$response = JsonResponse::create(0.1);
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
$this->assertSame('0.1', $response->getContent());
$this->assertEquals('0.1', $response->getContent());
$this->assertInternalType('string', $response->getContent());
$response = JsonResponse::create(true);
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);