Skip to content

chore: support PHPUnit 12 and 13 and clean up the test suite - #110

Merged
othillo merged 4 commits into
masterfrom
chore/phpunit-13
Nov 2, 2026
Merged

othillo merged 4 commits into
masterfrom
chore/phpunit-13

Conversation

@othillo

@othillo othillo commented Nov 2, 2026

Copy link
Copy Markdown
Member

This pull request replaces #109. Close #109 when this pull request is merged.

Problem

Dependabot changed the PHPUnit constraint to ^13.4 in #109. PHPUnit 13 needs PHP 8.4, and PHPUnit 12 needs PHP 8.3. This library supports PHP 8.2, so the PHP 8.2 and PHP 8.3 jobs cannot install the dependencies.

On PHPUnit 13, the test suite also shows deprecations, warnings and notices:

  • The any() matcher is deprecated.
  • Some mock objects have no expectations.
  • Two data providers give more arguments than the test method accepts.

Changes

  • Composer: allow phpunit/phpunit ^11.5 || ^12.5 || ^13.4. Composer selects the newest version that each PHP version supports. PHP 8.2 gets security fixes until 31 December 2026.
  • Tests: remove all PHPUnit 13 deprecations, warnings and notices. ToggleManagerTest uses real Toggle objects instead of mock objects. Each test class has #[CoversClass]. The tests have native types and use assertSame where the type or the instance is important.
  • phpunit.xml.dist: fail on risky tests, warnings, notices and PHPUnit deprecations. Require coverage metadata. The schema location stays at PHPUnit 11.5, because the file must work with all allowed versions.
  • php-cs-fixer: add @autoPHPUnitMigration:risky, php_unit_attributes, php_unit_data_provider_return_type and void_return.
  • PHPStan: add phpstan/phpstan-phpunit. Move the configuration to phpstan.dist.neon, set level max, and analyse test as well as lib. The tests have no baseline entries.
  • CI: add a job for the lowest dependencies on PHP 8.2. Set read-only permissions, cancel old pull request runs and set fail-fast: false. Show PHPStan errors as annotations.
  • Dependabot: use versioning-strategy: widen, so that an update adds a new major version to the constraint and does not remove the old one. Group the updates and check weekly.

Items to review

  • psr/http-message: ^1.1 || ^2.0 is a new require-dev entry. Predis 3 declares support for psr/http-message 1.0, but its Stream class is not compatible with 1.0. Without this entry, the lowest job fails with a fatal error.
  • The workflow was disabled because of inactivity. I enabled it again.

Verification

I ran each matrix job in Docker with the same Composer resolution and a Redis server:

PHP PHPUnit Result
8.2 11.5.57 OK (232 tests, 260 assertions)
8.2, lowest dependencies 11.5.50 OK (232 tests, 260 assertions)
8.3 12.5.43 OK (232 tests, 260 assertions)
8.4 13.4.6 OK (232 tests, 260 assertions)
8.5 13.4.6 OK (232 tests, 260 assertions)

PHPStan reports no errors, php-cs-fixer finds no files to fix, composer validate --strict passes and composer audit finds no advisories.

Not in this pull request

  • The PHPStan baseline for lib has about 60 entries. To remove them, the library code needs types. Some of these types change public method signatures, and that can break subclasses. Do this in a separate pull request.
  • The Symfony constraints ^8.0 also allow Symfony 8.0, which has no support. A change to ^8.1 is a policy decision.

Allow PHPUnit 11.5, 12.5 and 13.4. Composer selects the newest
version that the PHP version supports.

PHPUnit 13 needs PHP 8.4 and PHPUnit 12 needs PHP 8.3. This library
supports PHP 8.2, so the constraint keeps PHPUnit 11.5. PHP 8.2 gets
security fixes until 31 December 2026.

This change replaces #109.
That pull request sets the constraint to ^13.4, and the PHP 8.2 and
PHP 8.3 jobs then cannot install the dependencies.
Remove the deprecations, warnings and notices that PHPUnit 13 shows:

- Use real Toggle objects in ToggleManagerTest instead of mock objects
  without expectations and the deprecated any() matcher.
- Give each test method the full set of data provider arguments.
- Add #[CoversClass] to each test class.
- Use assertSame instead of assertEquals for scalar values and for
  objects that must be the same instance.
- Add native types and PHPDoc types to the test code.

Make phpunit.xml.dist stricter. PHPUnit now fails on risky tests,
warnings, notices and PHPUnit deprecations, and it needs coverage
metadata on each test class. The schema location points to PHPUnit
11.5, because the configuration must work with all allowed versions.

Add the @autoPHPUnitMigration:risky, php_unit_attributes,
php_unit_data_provider_return_type and void_return rules to
php-cs-fixer.
Add phpstan/phpstan-phpunit. The extension knows the PHPUnit mock and
assertion API, and its rules find incorrect PHPUnit usage.

Move the configuration to phpstan.dist.neon. A developer can then
override it with a local phpstan.neon file. The configuration now
sets level max and analyses lib and test. The baseline does not
change, and it contains no entries for the tests.

Make the phpstan target use the configuration. Fix the .PHONY
declaration of the phpstan target. Add a coverage target.
Add a job that installs the lowest allowed dependencies on PHP 8.2.
The job runs only on the lowest supported PHP version, because the
oldest releases of some dependencies are older than the newer PHP
versions.

Predis 3 declares support for psr/http-message 1.0, but its Stream
class is not compatible with that version. Require psr/http-message
1.1 or later in require-dev, so that the lowest job can install a
working set of packages.

Other changes to the workflow:

- Set the permissions of the token to read-only.
- Cancel a pull request run when a newer run starts.
- Set fail-fast to false, so that each PHP version shows its result.
- Remove the fail-fast variable from the setup-php step. The step
  does not read it.
- Install the highest dependencies explicitly. The repository does
  not contain a composer.lock file.
- Show PHPStan errors as annotations on the pull request.

Configure Dependabot to widen the version constraints, so that an
update does not remove support for an older PHP version. Group the
Symfony and development tool updates, check weekly, and use
Conventional Commits prefixes.
@othillo
othillo merged commit fa61bc3 into master Nov 2, 2026
7 checks passed
@othillo
othillo deleted the chore/phpunit-13 branch November 2, 2026 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant