Skip to content

Floating point values trigger deprecation warning #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
madman-81 opened this issue May 30, 2025 · 0 comments
Open

Floating point values trigger deprecation warning #75

madman-81 opened this issue May 30, 2025 · 0 comments

Comments

@madman-81
Copy link

PHP 8.4.1, PHPUnit 12.1.6 and json-diff 3.12.1

The unit test below triggers deprecation warnings.

<?php

namespace Tests;

use PHPUnit\Framework\TestCase;
use Swaggest\JsonDiff\JsonDiff;

class SwaggestTest extends TestCase
{
    public function testJsonTriggerConversionWarning()
    {
        $string1 = '[{"amount":1.2},{"amount":372}]';
        $string2 = '[{"amount":372},{"amount":1.2}]';

        $this->assertNotEquals($string1, $string2);
        $this->assertTrue(
            new JsonDiff(json_decode($string1), json_decode($string2), JsonDiff::REARRANGE_ARRAYS)->getDiffCnt() == 0
        );
    }
}
PHPUnit 12.1.6 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.4.1
Configuration: C:\project\phpunit.xml
Time: 00:00.021, Memory: 10.00 MB

1 test triggered 5 PHP deprecations:

1) C:\project\vendor\swaggest\json-diff\src\JsonDiff.php:455
Implicit conversion from float 1.2 to int loses precision

Triggered by:

* Tests\SwaggestTest::testJsonTriggerConversionWarning
  C:\project\tests\SwaggestTest.php:9

2) C:\project\vendor\swaggest\json-diff\src\JsonDiff.php:459
Implicit conversion from float 1.2 to int loses precision

Triggered by:

* Tests\SwaggestTest::testJsonTriggerConversionWarning
  C:\project\tests\SwaggestTest.php:9

3) C:\project\vendor\swaggest\json-diff\src\JsonDiff.php:499
Implicit conversion from float 1.2 to int loses precision

Triggered by:

* Tests\SwaggestTest::testJsonTriggerConversionWarning
  C:\project\tests\SwaggestTest.php:9

4) C:\project\vendor\swaggest\json-diff\src\JsonDiff.php:500
Implicit conversion from float 1.2 to int loses precision

Triggered by:

* Tests\SwaggestTest::testJsonTriggerConversionWarning
  C:\project\tests\SwaggestTest.php:9

5) C:\project\vendor\swaggest\json-diff\src\JsonDiff.php:511
Implicit conversion from float 1.2 to int loses precision

Triggered by:

* Tests\SwaggestTest::testJsonTriggerConversionWarning
  C:\project\tests\SwaggestTest.php:9

OK, but there were issues!
Tests: 1, Assertions: 2, Deprecations: 5.

Process finished with exit code 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant