Skip to content

Commit

Permalink
Use AsserEquals for floating-point values
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mmokhi authored and nicolas-grekas committed May 28, 2019
1 parent bb9a67d commit 0cef5f3
Showing 1 changed file with 4 additions and 2 deletions.
Expand Up @@ -52,7 +52,8 @@ public function testConstructorWithSimpleTypes()
$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());
Expand Down Expand Up @@ -140,7 +141,8 @@ public function testStaticCreateWithSimpleTypes()

$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);
Expand Down

0 comments on commit 0cef5f3

Please sign in to comment.