Skip to content
Latchkey

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.

composer
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.

.github/workflows/ci.yml
- uses: shivammathur/setup-php@v2
  with:
    php-version: '8.2'
- run: vendor/bin/phpunit

Or pin PHPUnit to a PHP-compatible major

If you must stay on an older PHP, constrain PHPUnit to a major that supports it.

Terminal
composer require --dev phpunit/phpunit:^9
composer update phpunit/phpunit

How 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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →