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

Tests: make test suite compatible with PHPUnit 10.x #483

Merged
merged 13 commits into from Jun 12, 2023

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jun 12, 2023

Composer: update the PHPUnit Polyfills

A PHPUnit 10 compatible version of the PHPUnit Polyfills has been released, so let's start using it.

Ref:

Tests/PolyfilledTestCase: make compatible with PHPUnit Polyfills 2.x

As the available traits are different between the 1.x and 2.x versions of the PHPUnit Polyfills, two different class definitions are needed.

This change uses the available PHPUnit Polyfills version number to load the correct class.

Tests/ConfigDataTest: switch to the PHPUnit Polyfills TestCase

Tests: make dataproviders static

As of PHPUnit 10, data providers are (again) expected to be static methods.

This updates the test suite to respect that.

Includes removing the use of $this from select data providers.

Refs:

Tests/SpacerFixer: make data providers static for compatibility with PHPUnit 10

Tests/InterpolatedVariablesTest: make data providers static for compatibility with PHPUnit 10

Tests/[NoFile]Cache/SetTest: remove use of the remove PHPUnit TestCase::getName() method

... in favour of just using a randomly generated ID for the cache.

Tests/HasNewLineSupportTest: work round removal of the setOutputCallback() method

PHPUnit 10.0 removed the TestCase::setOutputCallback() method without replacement.

Refs:

Tests/AbstractArrayDeclarationSniffTest: various tweaks and improvements

Tests: add new ExpectWithConsecutiveArgs helper trait

... to provide a work-around for the removal of the InvocationMocker->withConsecutive() method, which was removed without replacement in PHPUnit 10.0.

Refs:

Tests/AbstractArrayDeclarationSniffTest: implement use of the ExpectWithConsecutiveArgs helper

Tests/AbstractArrayDeclarationSniffTest: work around for MockBuilder::setMethods() removal

Please note:

  • The getMockBuilder() class is also deprecated now, so replacing with another method call on the MockBuilder class will only work in the short/medium term and in a future iteration, this will have to be refactored again.
  • Also the `getMockForAbstractClass method is also deprecated and expected to be removed in PHPUnit 12.

Refs:

PHPUnit: add separate configuration for PHPUnit 10

PHPUnit 10 makes significant changes to the configuration file.
While there is a --migrate-configuration option available in PHPUnit, that doesn't get us a well enough converted configuration file, so instead use a separate phpunit10.xml.dist file for running the tests on PHPUnit 10 with an optimal configuration.

Includes

  • Adding separate scripts to the composer.json file to make this more obvious for contributors.
  • Updating the GH Actions workflows to take the new configuration file into account when appropriate.
  • Selectively not using the --repeat option, which was removed without replacement in PHPUnit 10.

jrfnl added 13 commits June 6, 2023 23:02
A PHPUnit 10 compatible version of the PHPUnit Polyfills has been released, so let's start using it.

Ref:
* https://github.com/Yoast/PHPUnit-Polyfills/releases/tag/2.0.0
As the available traits are different between the 1.x and 2.x versions of the PHPUnit Polyfills, two different class definitions are needed.

This change uses the available PHPUnit Polyfills version number to load the correct class.
As of PHPUnit 10, data providers are (again) expected to be `static` methods.

This updates the test suite to respect that.

Includes removing the use of `$this` from select data providers.

Refs:
* sebastianbergmann/phpunit@9caafe2
* sebastianbergmann/phpunit 5100
…se::getName()` method

... in favour of just using a randomly generated ID for the cache.
…back()` method

PHPUnit 10.0 removed the `TestCase::setOutputCallback()` method without replacement.

Refs:
* sebastianbergmann/phpunit 5319
... to provide a work-around for the removal of the `InvocationMocker->withConsecutive()` method, which was removed without replacement in PHPUnit 10.0.

Refs:
* sebastianbergmann/phpunit 4026
* sebastianbergmann/phpunit 4255
* sebastianbergmann/phpunit 4564
…::setMethods()` removal

Please note:
* The `getMockBuilder()` class is also deprecated now, so replacing with another method call on the `MockBuilder` class will only work in the short/medium term and in a future iteration, this will have to be refactored again.
* Also the `getMockForAbstractClass method is also deprecated and expected to be removed in PHPUnit 12.

Refs:
* sebastianbergmann/phpunit 3687#issuecomment-492537584
* sebastianbergmann/phpunit 3770
* sebastianbergmann/phpunit 3769
* sebastianbergmann/phpunit 4775
PHPUnit 10 makes significant changes to the configuration file.
While there is a `--migrate-configuration` option available in PHPUnit, that doesn't get us a well enough converted configuration file, so instead use a separate `phpunit10.xml.dist` file for running the tests on PHPUnit 10 with an optimal configuration.

Includes
* Adding separate scripts to the `composer.json` file to make this more obvious for contributors.
* Updating the GH Actions workflows to take the new configuration file into account when appropriate.
* Selectively not using the `--repeat` option, which was [removed without replacement](sebastianbergmann/phpunit#5174) in PHPUnit 10.
@jrfnl jrfnl added this to the 1.0.x Next milestone Jun 12, 2023
@jrfnl jrfnl merged commit 4a4ea67 into develop Jun 12, 2023
51 checks passed
@jrfnl jrfnl deleted the feature/make-tests-compatible-with-phpunit-10 branch June 12, 2023 01:08
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.

None yet

1 participant