Skip to content

Tests: tweaks for PHPUnit 10.x compatibility#64

Merged
jrfnl merged 1 commit into
developfrom
feature/PHPUnit-10-tweak
Nov 3, 2021
Merged

Tests: tweaks for PHPUnit 10.x compatibility#64
jrfnl merged 1 commit into
developfrom
feature/PHPUnit-10-tweak

Conversation

@jrfnl

@jrfnl jrfnl commented Nov 3, 2021

Copy link
Copy Markdown
Collaborator

Initial tweaks to make the tests compatible with PHPUnit 10.x, which enforces a mixed return type for the TestCase::runTest() method.

To test the TestListener, prior to PHPUnit 7.0, overloading the runTest() method works best, but as of PHPUnit 10.0, the runTest() method has a mixed return type declaration (PHP 8.0+).
However, since PHPUnit 7.0, testing the TestListener also works when the test name with which the TestCase is instantiated is not runTest().

So either way, the fixtures used for the TestListener tests need to be duplicated and have two variations.

Now the choice was which option to choose:

  • Duplicate the classes and add a return type to the runTest() method.
  • Duplicate the classes and rename the test method.

I investigated both options and have decided to implement option 2 as void is not accepted as covariant with mixed and these methods are all void methods, so adding mixed as the return type would be misrepresenting the functionality.

The toggle for which test class to load for the various tests has been implemented with a helper method.

Initial tweaks to make the tests compatible with PHPUnit 10.x, which enforces a `mixed` return type for the `TestCase::runTest()` method.

To test the TestListener, prior to PHPUnit 7.0, overloading the `runTest()` method works best, but as of PHPUnit 10.0, the `runTest()` method has a `mixed` return type declaration (PHP 8.0+).
However, since PHPUnit 7.0, testing the TestListener also works when the test name with which the `TestCase` is instantiated is not `runTest()`.

So either way, the fixtures used for the TestListener tests need to be duplicated and have two variations.

Now the choice was which option to choose:
* Duplicate the classes and add a return type to the `runTest()` method.
* Duplicate the classes and rename the test method.

I investigated both options and have decided to implement option 2 as `void` is not accepted as covariant with `mixed` and these methods are all `void` methods, so adding `mixed` as the return type would be misrepresenting the functionality.

The toggle for which test class to load for the various tests has been implemented with a helper method.
@jrfnl jrfnl added this to the 1.x Next Release milestone Nov 3, 2021
@jrfnl jrfnl merged commit 0670f2e into develop Nov 3, 2021
@jrfnl jrfnl deleted the feature/PHPUnit-10-tweak branch November 3, 2021 16:25
@jrfnl jrfnl removed the yoastcs/qa label Nov 23, 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.

1 participant