PHPUnit "requires PHP X" in CI
Each major PHPUnit release sets a minimum PHP version. When CI installs (or restores) a PHPUnit that needs a newer PHP than the runner runs, PHPUnit refuses to start and reports the required version.
What this error means
Running PHPUnit fails before any test with "This version of PHPUnit is supported on PHP X.Y and Z. You are using PHP A.B." or "requires PHP >= X". The PHP and PHPUnit versions are out of step.
This version of PHPUnit is supported on PHP 8.2 and PHP 8.3.
You are using PHP 8.1.27.Common causes
PHPUnit version newer than the CI PHP
composer.json (or a global install) pulled a PHPUnit major that requires a PHP the runner does not provide.
PHP and tooling versions drifted apart
The CI PHP was pinned to an older version while PHPUnit was allowed to float to a newer major.
How to fix it
Raise the CI PHP to PHPUnit’s minimum
Provision a PHP version PHPUnit supports.
- uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- run: vendor/bin/phpunitOr pin PHPUnit to a PHP-compatible major
If you must stay on an older PHP, constrain PHPUnit to a major that supports it.
composer require --dev phpunit/phpunit:^9
composer update phpunit/phpunitHow to prevent it
- Keep the CI PHP version and PHPUnit major aligned.
- Pin phpunit/phpunit to a range your supported PHP versions satisfy.
- Use a matrix so each PHP version installs a compatible PHPUnit.