Skip to content

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

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

othillo merged 6 commits into
masterfrom
chore/phpunit-13

Conversation

@othillo

@othillo othillo commented Nov 2, 2026

Copy link
Copy Markdown
Member

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

Problem

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

On PHPUnit 13, ToggleTwigExtensionTest stops with an error, because returnValue() does not exist in PHPUnit 13. Other tests show deprecations and notices for the any() matcher and for mock objects without expectations.

The CI matrix had a symfony-version axis with 4.4, 5.2 and 5.3. No step used the axis, so each job installed the same Symfony version.

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 errors, deprecations and notices. Use stubs instead of mock objects without expectations. Replace assertTrue(true) with assertions on the event. Use the Symfony TokenStorage instead of the custom Tests/TokenStorage.php. Each test class has #[CoversClass] or #[CoversNothing], native types and assertSame.
  • phpunit.xml.dist: fail on risky tests, warnings, notices and PHPUnit deprecations. Require coverage metadata. Set APP_DEBUG=0. 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 Tests/. The tests have no baseline entries.
  • CI: use Symfony Flex with SYMFONY_REQUIRE to test Symfony 6.4, 7.4 and 8.1. Symfony 8.1 needs PHP 8.4, so the matrix does not run it on PHP 8.2 and PHP 8.3. Add a job for the lowest dependencies on PHP 8.2 with Symfony 6.4. 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

  • The minimum of symfony/framework-bundle in require is now ^6.4.13. This also applies to applications that use the bundle. With older versions, FrameworkBundle::boot() leaves an exception handler registered, and PHPUnit marks the functional test as risky. symfony/runtime (dev only) prevents this, but only from framework-bundle 6.4.13.
  • The minimum of twig/twig in require-dev is now ^3.28. This is the first version whose Twig integration test class works with PHPUnit 11 and later.
  • 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 Symfony Flex:

PHP Symfony 6.4 Symfony 7.4 Symfony 8.1 PHPUnit
8.2 OK, and OK with the lowest dependencies (6.4.0) OK not supported 11.5
8.3 OK OK not supported 12.5
8.4 OK OK OK 13.4
8.5 OK OK OK 13.4

Each job ran 29 tests with 46 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 the bundle code has about 15 entries. To remove them, the bundle code needs types. 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.

The constraint keeps ^11.5 because PHP 8.2 is still supported.
PHPUnit 12 requires PHP 8.3 and PHPUnit 13 requires PHP 8.4.
Composer selects the newest PHPUnit for each PHP version.
PHP 8.2 security support ends on 2026-12-31.

The Dependabot constraint ^13.4 removes PHP 8.2 and 8.3 from the
test matrix. This change replaces
#119.
PHPUnit 12 removed returnValue() and PHPUnit 13 deprecates any() and
reports mocks that have no expectations. The tests now use stubs for
these doubles.

Other changes:
- Replace the custom TokenStorage test double with the Symfony class.
- Replace the assertTrue(true) checks with assertions on the event.
- Remove a test that only repeated the setup of another test.
- Add CoversClass attributes, native types and assertSame.
- Enable the PHPUnit migration rules in PHP CS Fixer. These rules
  follow the lowest PHPUnit version in composer.json.
The configuration now fails on risky tests, warnings, notices and
PHPUnit deprecations. Each test class must declare what it covers.
The schema stays on PHPUnit 11.5 because the configuration must load
on all supported PHPUnit versions.

The functional tests boot the kernel with APP_DEBUG=0.
PHPStan now also analyses the Tests directory. The phpstan-phpunit
extension adds the PHPUnit types and rules. The configuration file
is now phpstan.dist.neon, so a developer can override it locally
with phpstan.neon. The level is set in this file and not in the
Makefile.

The baseline has no stale entries, so it stays the same.
The test suite failed with the lowest versions of the dependencies.

- twig/twig 3.28 is the first version with a Twig IntegrationTestCase
  that works with PHPUnit 11 and later.
- symfony/framework-bundle registers an exception handler when the
  kernel boots. PHPUnit marks the functional test as risky because
  the handler stays. With symfony/runtime installed, FrameworkBundle
  uses the existing handler. FrameworkBundle has this behaviour from
  version 6.4.13.

symfony/runtime is only a development dependency. The new floor of
symfony/framework-bundle also applies to applications that use the
bundle.
The old symfony-version axis listed Symfony 4.4, 5.2 and 5.3, and
no step read it. Symfony Flex now uses the axis to select Symfony
6.4, 7.4 or 8.1. The matrix excludes Symfony 8 on PHP 8.2 and 8.3.
One job tests the lowest dependency versions on PHP 8.2.

Other changes:
- Do not stop the other jobs when one job fails.
- Give the workflow read access to the repository contents only.
- Cancel a pull request run when a new commit replaces it.
- Install the highest versions in the jobs that do not use the matrix,
  because the repository has no lock file.
- Show PHPStan errors as annotations on the pull request.

Dependabot now runs weekly and groups the updates. It widens the
version constraints, so an update adds a new major version and keeps
the versions that are already supported.
@othillo
othillo merged commit 924ea99 into master Nov 2, 2026
13 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