Skip to content
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

AssertObjectEquals trait: polyfill the Assert::assertObjectEquals() method #38

Merged
merged 1 commit into from Jun 17, 2021

Commits on Jun 17, 2021

  1. AssertObjectEquals trait: polyfill the Assert::assertObjectEquals() m…

    …ethod
    
    PHPUnit 9.4.0 introduced the new `Assert::assertObjectEquals()` method.
    
    This commit:
    * Adds two traits with the same name.
        One to polyfill the method when not available in PHPUnit.
        The other to allow for `use`-ing the trait in PHPUnit versions in which the method is already natively available.
    * Adds an `InvalidComparisonMethodException` exception class.
        _PHPUnit natively throws a range of different exceptions._
        _The polyfill included in this library throws one exception type - the `InvalidComparisonMethodException` - with a range of different messages._
    * Logic to the custom autoloader which will load the correct trait depending on the PHPUnit version used.
    * Adds tests.
    
    As the polyfill contains logic to match the PHPUnit native implementation as closely as possible, while still being PHP and PHPUnit cross-version compatible, extensive unit tests have been added to ensure the behaviour of the polyfill matches that of the original function, with the exception of the _return type verification_.
    
    As return types were not available in PHP prior to PHP 7.0, the return type verification as done in the PHPUnit native implementation, has been replaced by a verification that the _returned value_ is of the required type.
    This provides the same safeguard as the PHPUnit native implementation, but in a PHP cross-version compatible manner.
    
    Note: the method uses `static::` to call the PHPUnit native functionality. This allows for existing method overloads in a child class of the PHPUnit native `TestCase` to be respected.
    
    Includes:
    * Adding information on the new polyfill to the README.
    * Adding the new polyfill to the existing `TestCases` classes.
    * Adding a few select exceptions to the PHPCS ruleset for the fixtures used in the tests.
    
    Refs:
     * sebastianbergmann/phpunit#4467
     * sebastianbergmann/phpunit#4707
     * sebastianbergmann/phpunit@1dba8c3
     * sebastianbergmann/phpunit@6099c5e
    jrfnl committed Jun 17, 2021
    Configuration menu
    Copy the full SHA
    cb1b31d View commit details
    Browse the repository at this point in the history