Skip to content

Floating point values trigger deprecation warning #75

@madman-81

Description

@madman-81

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @madman-81

        Issue actions

          Floating point values trigger deprecation warning · Issue #75 · swaggest/json-diff