digitalrevolution/phpunit-file-coverage-inspection
Define per-file code coverage thresholds from Clover coverage.xml, with directory/file overrides and optional uncovered-method rules. Fails builds with checkstyle or GitLab formatted reports so a single file can’t hide behind high overall coverage.
src/Lib/Config/ needing 100% coverage while legacy files tolerate 80%).phpfci.xml) enable hierarchical overrides (directory → file) and temporal exceptions (e.g., allow-uncovered-methods per file), reducing rigid global thresholds.coverage: 'reports/gitlab.errors.json').phpfci baseline coverage.xml --config phpfci.xml), critical for gradual enforcement in legacy codebases.| Risk Area | Mitigation Strategy |
|---|---|
| XML Schema Complexity | Validate phpfci.xml against provided XSD (phpfci.xsd). Use IDE plugins (e.g., PHPStorm) for schema-aware editing. |
| Path Resolution | Explicit --baseDir flag ensures consistent path handling across CI/local. Test with realpath()-normalized paths. |
| False Positives | Configure ignore-uncovered-methods for legacy files or edge cases (e.g., __construct with no logic). |
| Performance | Minimal overhead: Processes clover XML (not recompiling code). Benchmark with large codebases (e.g., 10K+ files). |
| Version Locking | Pin to v3.x (PHPUnit 12, Symfony 8) to avoid dependency conflicts. Use composer require digitalrevolution/phpunit-file-coverage-inspection:^3.0. |
test:
script: phpunit --coverage-clover coverage.xml
after_script:
- php vendor/bin/phpfci inspect coverage.xml --reportGitlab=gl-coverage.json --exit-code-on-failure
--exit-code-on-failure).baseline to auto-generate rules from current coverage.phpfci.xml as code evolves? Consider auto-generating rules from coverage trends.composer.json scripts:
"scripts": {
"test": "phpunit",
"coverage-check": "php vendor/bin/phpfci inspect coverage.xml --reportGitlab=gl-coverage.json --exit-code-on-failure"
}
- name: Upload coverage
uses: actions/upload-artifact@v3
with:
name: coverage-results
path: gl-coverage.json
composer.json (dev dependency):
composer require --dev digitalrevolution/phpunit-file-coverage-inspection:^3.0
php vendor/bin/phpfci baseline coverage.xml --config phpfci.xml --baseDir=.
--exit-code-on-failure).src/ = 90%, tests/ = 80%).src/Contracts/ = 100%).allow-uncovered-methods for new files).phpunit.xml or composer.json:
<php>
<env name="COVERAGE_EXIT_ON_FAILURE" value="1"/>
</php>
| Component | Compatibility Notes |
|---|---|
| PHPUnit Versions | Tested with 10, 11, 12. Laravel 9+ (PHPUnit 10) is fully supported. |
| Laravel Artisan | No direct integration, but can be called via Artisan::call() in custom commands. |
| Windows/Linux/macOS | CLI tool; works cross-platform (tested via GitHub Actions). |
| Parallel Testing | Supports multiple coverage files (e.g., from parallel PHPUnit runs). |
coverage.clover (default in Laravel’s phpunit.xml).php artisan test --coverage-clover=coverage.xml
php vendor/bin/phpfci inspect coverage.xml --reportGitlab=gl-coverage.json
phpcs or custom scripts.phpfci.xml may become outdated as files are renamed/moved.src/Lib/ instead of /var/www/project/src/Lib/).phpfci.xml like phpunit.xml—version-controlled and reviewed via PRs.--reportText for human-readable errors:
php vendor/bin/phpfci inspect coverage.xml --reportText
--baseDir matches the project root.coverage.clover is generated by PHPUnit (not a custom tool).coverage.clover to avoid reprocessing.phpunit --testsuite=Unit), generate per-suite coverage, then merge:
php vendor/bin/phpfci inspect coverage-unit.xml coverage-integration.xml
How can I help you explore Laravel packages today?