esi/phpunit-coverage-check
Reads PHPUnit clover/openclover XML coverage reports and computes overall coverage percentage. Fails CI with exit code 1 when coverage drops below a configurable threshold; exits successfully when the threshold is met. Useful for enforcing minimum test coverage.
Start by installing the package as a dev dependency: composer require --dev esi/phpunit-coverage-check:^3.1 (for PHP 8.3+) or pick the appropriate version per PHP compatibility (v2.x for PHP 8.2, v1.x for PHP 8.1). Then generate a Clover report by running phpunit --coverage-clover clover.xml (or --coverage-openclover for PHPUnit 12.2+), and immediately check coverage with vendor/bin/coverage-check clover.xml 90. If coverage falls below 90%, the command exits with code 1—ideal for CI gates. First use case: enforce coverage in CI pipelines using the provided GitHub Action or the CLI command.
Integrate via Composer scripts in composer.json (e.g., "coverage:check": "coverage-check clover.xml 90") to trigger from local or CI workflows. In GitHub Actions, use the dedicated action from the marketplace or wrap the CLI call in a step: php vendor/bin/coverage-check clover.xml 85. For custom logic (e.g., reporting to dashboards), use the CoverageCheck::nonConsoleCall() method to get formatted output as a string instead of CLI results. For pre-commit hooks, run the check against the current working tree’s coverage report—failures block commits. The --show-files (-F) flag offers per-file breakdown in a table for targeted fixes, and --only-percentage (-O) enables parsing-friendly output (e.g., for Slack/Teams notifications).
Ensure the Clover report uses the correct format: --coverage-clover (PHPUnit ≤12.1) vs. --coverage-openclover (PHPUnit ≥12.2). Use the outputFile in phpunit.xml to standardize the report path—don’t assume default locations. Watch out for --show-files ignoring --only-percentage; this is intentional to display file-level granularity. When running in environments with limited width (e.g., small terminal windows), use --table-width (-W) with --show-files to prevent wrapping. If using PHAR, always verify the GPG signature—skip this at your peril in production. Finally, the package requires PHP 8.3+, so verify PHP version before installing v3.x—use v2.x/v1.x for older runtimes.
How can I help you explore Laravel packages today?