Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
minor #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 #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
  • Loading branch information
nicolas-grekas committed May 28, 2019
2 parents bb9a67d + 0cef5f3 commit a26c6d3
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 a26c6d3

Please sign in to comment.