Skip to main content

Code Coverage Setup

php-ci images include a coverage driver so PHPUnit can emit text, HTML or Clover reports without extra image setup.

Quick coverage run

docker run --rm -v "$(pwd):/app" -w /app himanshuramavat/php-ci:8.3 bash -c '
composer install --no-interaction --prefer-dist &&
./vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml
'

PHPUnit configuration

Enable coverage in phpunit.xml:

<coverage>
<report>
<clover outputFile="coverage.xml"/>
<text outputFile="php://stdout" showUncoveredFiles="false"/>
</report>
</coverage>

GitHub Actions artifact

Upload Clover output for downstream tools (Codecov, SonarQube, etc.):

jobs:
test:
runs-on: ubuntu-latest
container:
image: himanshuramavat/php-ci:8.3
steps:
- uses: actions/checkout@v4
- run: composer install --no-interaction --prefer-dist
- run: ./vendor/bin/phpunit --coverage-clover=coverage.xml
- uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage.xml

Performance notes

  • Text summaries are cheap; HTML reports add I/O — generate them only when needed.
  • For Laravel projects, see the Laravel guide for php artisan test --coverage patterns.