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

Conversation

jrfnl
Copy link
Collaborator

@jrfnl jrfnl commented Jun 17, 2021

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:

Fixes #5

…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 jrfnl added this to the 1.0.0 milestone Jun 17, 2021
@jrfnl jrfnl merged commit 9970f5f into develop Jun 17, 2021
@jrfnl jrfnl deleted the feature/3-add-polyfill-assertobjectequals branch June 17, 2021 07:32
@jrfnl jrfnl removed the yoastcs/qa label Oct 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FR] Add polyfill for new assertObjectEquals()
1 participant