json-diff icon indicating copy to clipboard operation
json-diff copied to clipboard

Floating point values trigger deprecation warning

Open madman-81 opened this issue 8 months ago • 0 comments

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

madman-81 avatar May 30 '25 21:05 madman-81