Repository navigation
chore: support PHPUnit 12 and 13 and clean up the test suite - #110
Merged
Merged
Conversation
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.
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 #109. Close #109 when this pull request is merged.
Problem
Dependabot changed the PHPUnit constraint to
^13.4in #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:
any()matcher is deprecated.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.Toggleobjects instead of mock objects. Each test class has#[CoversClass]. The tests have native types and useassertSamewhere the type or the instance is important.@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 analysetestas well aslib. The tests have no baseline entries.fail-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
psr/http-message: ^1.1 || ^2.0is a newrequire-deventry. Predis 3 declares support for psr/http-message 1.0, but itsStreamclass is not compatible with 1.0. Without this entry, the lowest job fails with a fatal error.Verification
I ran each matrix job in Docker with the same Composer resolution and a Redis server:
PHPStan reports no errors, php-cs-fixer finds no files to fix,
composer validate --strictpasses andcomposer auditfinds no advisories.Not in this pull request
libhas 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.^8.0also allow Symfony 8.0, which has no support. A change to^8.1is a policy decision.