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: allow for running on PHPUnit 10/11 #162

Merged
merged 2 commits into from
Sep 10, 2024

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Sep 10, 2024

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

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

Refs:

Tests: allow for running on PHPUnit 10/11

Until now, the tests would run on PHPUnit 9 for PHP 7.3 and higher.

PHPUnit 10 (PHP 8.1+) was released in February 2023, PHPUnit 11 (PHP 8.2+) in February 2024 and the update for this test suite is quite painless, so let's allow for running the tests on PHPUnit 10 and 11 (with PHPUnit Polyfills 2.x/3.x).

This commit actions this.

Things to be aware of:

Handling of PHPUnit deprecations

Prior to PHPUnit 10.5.32 and PHPUnit 11.3.3, if the failOnDeprecation attribute was set (previously: convertDeprecationsToExceptions), tests runs would not only fail on PHP deprecation notices, but also on PHPUnit native deprecation notices when running on PHPUnit 10/11.

This undesirable behaviour has now (finally) been reverted, which makes updating test suites for compatibility with PHPUnit 10/11 a lot more straight-forward.

This is the reason that the minimum PHPUnit 10/11 versions in the composer.json file are set to such specific versions.

As part of this change, PHPUnit 10.5.32 and 11.3.3 introduce two new options for both the configuration file and as CLI arguments: displayDetailsOnPhpunitDeprecations and failOnPhpunitDeprecation, both of which will default to false.

These options have been added to the PHPUnit configuration for PHPUnit 10/11 to safeguard them against changes in the default value.

Test configuration file changes

The configuration file specification has undergone changes in PHPUnit 9.3, 10.0 and 10.1.

Most notably:

  • In PHPUnit 9.3, the manner of specifying the code coverage configuration has changed.
  • In PHPUnit 10.0, a significant number of attributes of the <phpunit> element were removed or renamed.
  • In PHPUnit 10.1, the manner for specifying the code coverage configuration was changed again.

While the --migrate-configuration command can upgrade a configuration for the changes in the format made in PHPUnit 9.3 and 10.1, some of the changes in the configuration format in PHPUnit 10 don't have one-on-one replacements and/or are not taken into account.

With that in mind, I deem it more appropriate to have a dedicated PHPUnit configuration file for PHPUnit 10+ to ensure the test run will behave as intended.

To that end:

  • The phpunit.xml.dist file has been renamed to phpunitlte9.xml.dist (for PHPUnit <= 9) and a new phpunit.xml.dist file has been added for PHPUnit 10+.
  • The renamed file is set to be excluded from release archives via .gitattributes and a potential local overload file for it is set to be ignored by default via the .gitignore file.
  • Additional scripts have been added to the composer.json file to run the tests either with the new or the old configuration file.
  • The GH Actions test workflow has been updated to select the correct configuration file based on the PHPUnit version on which the tests are being run.

Other command/config changes

Also note that the --coverage-cache <dir> CLI flag was deprecated in PHPUnit 10 and removed in PHPUnit 11. A generic cacheDirectory attribute is the recommended replacement (though a CLI option is also available).
The new attribute has been added to the PHPUnit 10+ config file and the directory it points to has been added to .gitignore.

Ref:

…lback()` method

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

Refs:
* sebastianbergmann/phpunit 5319
Until now, the tests would run on PHPUnit 9 for PHP 7.3 and higher.

PHPUnit 10 (PHP 8.1+) was released in February 2023, PHPUnit 11 (PHP 8.2+) in February 2024 and the update for this test suite is quite painless, so let's allow for running the tests on PHPUnit 10 and 11.

This commit actions this.

Things to be aware of:

Handling of PHPUnit deprecations

Prior to PHPUnit 10.5.32 and PHPUnit 11.3.3, if the `failOnDeprecation` attribute was set (previously: `convertDeprecationsToExceptions`), tests runs would not only fail on PHP deprecation notices, but also on PHPUnit native deprecation notices when running on PHPUnit 10/11.

This undesirable behaviour has now (finally) been reverted, which makes updating test suites for compatibility with PHPUnit 10/11 a lot more straight-forward.

This is the reason that the minimum PHPUnit 10/11 versions in the `composer.json` file are set to such specific versions.

As part of this change, PHPUnit 10.5.32 and 11.3.3 introduce two new options for both the configuration file and as CLI arguments: `displayDetailsOnPhpunitDeprecations` and `failOnPhpunitDeprecation`, both of which will default to `false`.

These options have been added to the PHPUnit configuration for PHPUnit 10/11 to safeguard them against changes in the default value.

Test configuration file changes

The configuration file specification has undergone changes in PHPUnit 9.3, 10.0 and 10.1.

Most notably:
* In PHPUnit 9.3, the manner of specifying the code coverage configuration has changed.
* In PHPUnit 10.0, a significant number of attributes of the `<phpunit>` element were removed or renamed.
* In PHPUnit 10.1, the manner for specifying the code coverage configuration was changed again.

While the `--migrate-configuration` command can upgrade a configuration for the changes in the format made in PHPUnit 9.3 and 10.1, some of the changes in the configuration format in PHPUnit 10 don't have one-on-one replacements and/or are not taken into account.

With that in mind, I deem it more appropriate to have a dedicated PHPUnit configuration file for PHPUnit 10+ to ensure the test run will behave as intended.

To that end:
* The `phpunit.xml.dist` file has been renamed to `phpunitlte9.xml.dist` (for PHPUnit <= 9) and a new `phpunit.xml.dist` file has been added for PHPUnit 10+.
* The renamed file is set to be excluded from release archives via `.gitattributes` and a potential local overload file for it is set to be ignored by default via the `.gitignore` file.
* Additional scripts have been added to the `composer.json` file to run the tests either with the new or the old configuration file.
* The GH Actions `test` workflow has been updated to select the correct configuration file based on the PHPUnit version on which the tests are being run.

Other command/config changes

Also note that the `--coverage-cache <dir>` CLI flag was deprecated in PHPUnit 10 and removed in PHPUnit 11. A generic `cacheDirectory` attribute is the recommended replacement (though a CLI option is also available).
The new attribute has been added to the PHPUnit 10+ config file and the directory it points to has been added to `.gitignore`.

Ref:
* https://phpunit.de/announcements/phpunit-11.html
* https://phpunit.de/announcements/phpunit-10.html
@jrfnl jrfnl added this to the 1.x Next Release milestone Sep 10, 2024
@jrfnl jrfnl merged commit 1faeaaa into stable Sep 10, 2024
35 checks passed
@jrfnl jrfnl deleted the feature/update-for-phpunit-10-11 branch September 10, 2024 02:38
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