Repository navigation
chore: support PHPUnit 12 and 13 and clean up the test suite - #120
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request replaces #119. Close #119 when this pull request is merged.
Problem
Dependabot changed the PHPUnit constraint to
^13.4in #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,
ToggleTwigExtensionTeststops with an error, becausereturnValue()does not exist in PHPUnit 13. Other tests show deprecations and notices for theany()matcher and for mock objects without expectations.The CI matrix had a
symfony-versionaxis with 4.4, 5.2 and 5.3. No step used the axis, so each job installed the same Symfony version.Changes
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.assertTrue(true)with assertions on the event. Use the SymfonyTokenStorageinstead of the customTests/TokenStorage.php. Each test class has#[CoversClass]or#[CoversNothing], native types andassertSame.APP_DEBUG=0. The schema location stays at PHPUnit 11.5, because the file must work with all allowed versions.@autoPHPUnitMigration:risky,php_unit_attributes,php_unit_data_provider_return_typeandvoid_return.phpstan/phpstan-phpunit. Move the configuration tophpstan.dist.neon, set level max, and analyseTests/. The tests have no baseline entries.SYMFONY_REQUIREto 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 setfail-fast: false. Show PHPStan errors as annotations.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
symfony/framework-bundleinrequireis 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.twig/twiginrequire-devis now^3.28. This is the first version whose Twig integration test class works with PHPUnit 11 and later.Verification
I ran each matrix job in Docker with the same Composer resolution and Symfony Flex:
Each job ran 29 tests with 46 assertions. PHPStan reports no errors, php-cs-fixer finds no files to fix,
composer validate --strictpasses andcomposer auditfinds no advisories.Not in this pull request
^8.0also allow Symfony 8.0, which has no support. A change to^8.1is a policy decision.