Run PHPUnit in GitHub Actions with PHP matrix, Xdebug coverage, and Codecov upload.
PHPUnit in CI/CD
# GitHub Actions — .github/workflows/tests.yml
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
php: [8.2, 8.3]
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: pdo_sqlite, xdebug
coverage: xdebug
- name: Install dependencies
run: composer install --no-progress
- name: Run tests with coverage
run: ./vendor/bin/phpunit --coverage-clover=coverage.xml
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
file: coverage.xml