jaschilz/php-coverage-badger
Generate an SVG code coverage badge from a PHPUnit Clover XML report. Install via Composer and run the included CLI to turn clover.xml into a coverage.svg badge for your CI or README.
phpunit --coverage-clover, but lacks a native badge generation solution. This package fills that gap without requiring deep architectural changes.phpunit --coverage-clover=path/to/clover.xml).README.md, CHANGELOG.md).| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Deprecation Risk | Last release in 2017; no active maintenance. | Fork the repo to apply minor fixes (e.g., PHP 8+ compatibility) or use as a reference to build a custom solution. |
| PHP Version Support | Likely PHP 5.6–7.x; may need updates for PHP 8+. | Test compatibility or patch the package for Laravel’s PHP version (8.0+). |
| XML Parsing Issues | PHPUnit’s Clover XML format may evolve, breaking badge generation. | Validate XML schema in CI (e.g., xmllint) before badge generation. |
| SVG Customization | Limited badge styling options (hardcoded colors/sizes). | Post-process SVG with a tool like svgo or modify the package’s template logic. |
| CI/CD Integration | Requires manual CLI invocation; may not fit into Laravel’s task runners. | Wrap in a custom Artisan command or CI script (e.g., GitHub Actions). |
README) or internal dashboards (e.g., team metrics)?simplexml_load_file) preferable?php artisan coverage:badge) for Laravel-specific workflows.public/ directory.Phase 1: Proof of Concept (PoC)
composer require --dev jaschilz/php-coverage-badger
./vendor/bin/phpunit --coverage-clover=clover.xml
./vendor/bin/php-coverage-badger clover.xml public/coverage.svg
README.md.Phase 2: CI/CD Integration
- name: Generate Coverage Badge
run: vendor/bin/php-coverage-badge clover.xml public/coverage.svg
gh-pages branch.Phase 3: Laravel-Specific Abstraction (Optional)
app/Console/Commands/GenerateCoverageBadge.php):
use Jaschilz\PHPCoverageBadger\PHPCoverageBadger;
public function handle() {
$badger = new PHPCoverageBadger(storage_path('clover.xml'));
$badger->generate(storage_path('coverage.svg'));
}
app/Console/Kernel.php:
protected $commands = [
Commands\GenerateCoverageBadge::class,
];
| Component | Compatibility Notes |
|---|---|
| PHP Version | Test with Laravel’s PHP version (8.0+); patch if needed. |
| PHPUnit | Works with PHPUnit 6–10; ensure --coverage-clover flag is used. |
| Laravel | No direct conflicts; treat as a build-time dependency (dev-only). |
| CI Systems | Compatible with GitHub Actions, GitLab CI, etc.; requires shell access. |
| SVG Rendering | Badges must be hosted on a server or CDN (e.g., Shields.io, GitHub Pages). |
--coverage-clover).public/coverage.svg).simplexml) if maintenance becomes critical.xmllint clover.xml.How can I help you explore Laravel packages today?