Run your PHP tests across multiple versions and operating systems using GitHub Actions matrix strategy.
A matrix strategy lets you run the same workflow job across multiple PHP versions, operating systems, and configurations in parallel. This is the most effective way to ensure your code works everywhere your users run it.
The following workflow runs tests on Ubuntu, Windows, and macOS against PHP 8.2 through 8.5. Each combination becomes a separate job that runs in parallel.
Including specific PHP and PHPUnit version combinations
Use the include: key to add specific combinations that fall outside the main matrix. This is useful when you need to support an older PHP version that requires a pinned tool version.
To run tests on both amd64 and arm64 architectures, use shivammathur/node container images. These images have compatible Node.js and PHP installed for setup-php on Ubuntu and Debian runners.PHP 5.6 to PHP 8.5 are supported on multiple architectures through this approach.
The container image tag format is shivammathur/node:php-{version}-{ubuntu-version}-{arch}. The include: entries map each architecture to the appropriate runner label.
By default, GitHub Actions cancels all in-progress jobs when one matrix job fails. Set fail-fast: false to let all jobs complete so you can see which combinations fail.
Test both the minimum and stable versions of your Composer dependencies by adding a prefer dimension to your matrix. This is especially useful for libraries that need to support a range of dependency versions.
The GitHub-hosted runner label ubuntu-latest currently maps to Ubuntu 24.04. Pin to a specific version like ubuntu-24.04 in production workflows to avoid unexpected changes when the latest label is updated.