Skip to content

Improve testing against PHPUnit version 10, 11, and 12 #116

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

Merged
merged 21 commits into from
Apr 17, 2025

Conversation

delatrie
Copy link
Contributor

@delatrie delatrie commented Apr 16, 2025

Context

#115 has added support for PHP 8.4 and PHPUnit 11 and 12.

This PR continues the efforts to

  • Clarify the exact versions of the deps allure-phpunit requires.
  • Make sure we have a CI workflow that tests against all supported versions of PHP and PHPUnit.

Supported PHP versions

We support all versions currently supported by the PHP devs, see https://www.php.net/supported-versions. Currently, those are ^8.1 || ^8.2 || ^8.3 || ^8.4.

Supported PHPUnit versions

Currently, we aim to support PHPUnit 10, 11, and 12. Due to the requirements of brianium/paratest (our dev dependency), we can't install the following PHPUnit versions:

  • 10.0.0-10.0.4
  • 12.0.0

Since we use the same PHPUnit installation for running our tests and the Allure adapter for PHPUnit, we can't test against the versions above either in CI or on personal machines. If a bug is reported with one of those versions, we cannot write a test that reproduces it without tweaking the dependency spec.

With that in mind, this PR sets the declared supported versions of PHPUnit to ^10.0.5 || ^11 || ^12.0.1.

PHPUnit versions in the CI matrix

Previously, we only tested against PHPUnit ^10 with and without --prefer-lowest.

After versions ^11 and ^12 were added to require, that testing scheme became incomplete: it skipped PHPUnit 11.

This PR adds a PHPUnit version dimension to the testing CI job, which enables testing against the whole range of the supported PHPUnit versions.

There are some incompatibilities between PHP, PHPUnit, and ParaTest (see include and exclude in build.yml).

Additionally, we have some tests that mock PHPUnit\Event\Code\Test, which is readonly starting from PHPUnit 11.0.0. Those tests fail when run with PHPUnit 11.0 and 11.1. One solution would be skipping the tests if mocking fails, but for now, the PR further constrains PHPUnit 11 to ^11.2 in the CI workflow.

The XML schema for the legacy (v10) PHPUnit config files was reverted to https://schema.phpunit.de/10.0/phpunit.xsd. We are now using a PHP script to get the PHPUnit version at runtime and choose the correct config file based on it.

GarbageCollectorStatus compatibility

PHPUnit\Event\Telemetry\GarbageCollectorStatus was introduced in PHPUnit 10.1.0. Its constructor requires four extra parameters starting from 10.3.0. The PR fixes EventTestTrait to account for all three cases by checking the number of constructor parameters with ReflectionClass.

#[CoversClass] and #[CoversTrait]

We use #[CoversClass] to indicate to PHPUnit that only ExceptionDetailsTrait's methods should be marked as covered by the tests in ExceptionDetailsTraitTest. Using traits with #[CoversClass] was an undocumented (and untested) feature of PHPUnit, which became broken at some point. Then, #[CoversTrait] was introduced in 11.2.0, and PHPUnit's devs advised to use it with traits instead of #[CoversClass].

The PR refactors ExceptionDetailsTraitTest to be conditionally defined with the correct attribute, which supports both old and new mechanisms depending on whether PHPUnit\Framework\Attributes\CoversTrait exists or not.

In 11.4.0, #[CoversTrait] was declared as deprecated: the devs had discovered that #[CoversClass] also covers the target's traits and decided the new attribute wasn't needed in the first place. They reinstated it in 11.5.4 and kept it in version 12 to target traits without targeting the surrounding class. See the discussion here.

Note

We are ignoring PSR1.Classes.ClassDeclaration.MultipleClasses in ExceptionDetailsTraitTest.php because it essentially declares a single class used outside.

Psalm fixes

The 0.19.4 release of psalm/plugin-phpunit has introduced new checks on data providers for PHPUnit tests. The ones we have in DataProviderTest.php failed them (see here).

The PR applies the correct type annotations to the data provider functions, which fixes the issues.

Dependency updates

  • Remove phpunit/phpunit from require-dev.
  • Widen the supported versions of brianium/paratest from ^7.3 to ^7.
  • Bump vimeo/psalm to ^6.10.
  • Bump psalm/plugin-phpunit to ^0.19.5.

PHPUnit configuration update

The PR bumps the XML schema of the default PHPUnit config files we use to https://schema.phpunit.de/12.1/phpunit.xsd.

Ideally, we should use a separate config file for each major PHPUnit version we test against. However, in our case, the config file is compatible with versions 11 and 12.

@delatrie delatrie force-pushed the phpunit-deps-range-fix branch from 488a5f3 to ee13265 Compare April 16, 2025 18:10
@delatrie delatrie force-pushed the phpunit-deps-range-fix branch from ee13265 to f235501 Compare April 16, 2025 18:17
@delatrie delatrie force-pushed the phpunit-deps-range-fix branch from fe5e99c to 6139eb3 Compare April 16, 2025 21:08
@delatrie delatrie requested a review from baev April 17, 2025 19:38
@delatrie delatrie marked this pull request as ready for review April 17, 2025 19:39
@baev baev merged commit be8b5ef into main Apr 17, 2025
55 checks passed
@baev baev deleted the phpunit-deps-range-fix branch April 17, 2025 19:41
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.

2 participants