Comprehensive JSON coverage reporter for PHPUnit. Reports all 5 coverage metrics: Line, Branch, Path, Function, and Class.
PHPUnit provides code coverage data via php-code-coverage, but it does not offer a native JSON output format.
Existing formats such as HTML, Clover XML, or Cobertura XML are designed for human reading or specific CI tools. They are not convenient for programmatic consumption.
This package fills that gap by exposing coverage data as structured JSON.
There has been prior discussion about adding JSON output support directly to php-code-coverage:
sebastianbergmann/php-code-coverage#829
As of now, JSON output is not available natively. This package provides an external solution.
This library is implemented as a PHPUnit extension.
It accesses the raw coverage data during runtime and serializes it into JSON.
- No XML parsing
- No post-processing required
- Direct access to in-memory coverage data
- CI pipelines (custom coverage checks)
- Programmatic analysis (scripts, tooling)
- Frontend dashboards
- Integration with other systems
| PHPUnit | php-code-coverage | Status |
|---|---|---|
| 10.x | 10.x | ✅ Tested |
| 11.x | 11.x | ✅ Tested |
| 12.x | 12.x | ✅ Tested |
| 13.x | 13.x | ✅ Tested |
See Version Compatibility for detailed test results.
composer require --dev turkeryildirim/phpunit-json-coverage-reportAdd the reporter to your phpunit.xml:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit>
<!-- ... other config ... -->
<extensions>
<bootstrap class="Turker\PHPUnitCoverageReporter\JsonReporterExtension">
<!-- Optional: Custom output path (default: coverage.json) -->
<parameter name="outputFile" value="coverage.json"/>
<!-- Optional: Filter metrics (default: all) -->
<!-- Available: lines, branches, paths, functions, classes -->
<parameter name="metrics" value="lines,branches,functions,classes"/>
</bootstrap>
</extensions>
</phpunit>Run tests with coverage:
vendor/bin/phpunitA coverage.json file will be generated in your project root.
- Extended README - Detailed usage, output format, and all metrics explained
- Contributing Guide - For developers who want to fork and extend
- Version Compatibility - Tested version combinations
- Example Output - Sample JSON output
MIT License - see LICENSE for details.