turkeryildirim / phpunit-json-coverage-report
Comprehensive JSON coverage reporter for PHPUnit.
Package info
github.com/turkeryildirim/phpunit-json-coverage-report
pkg:composer/turkeryildirim/phpunit-json-coverage-report
Requires
- php: ^8.1
- phpunit/php-code-coverage: ^10.0 || ^11.0 || ^12.0 || ^13.0 || ^14.0
- phpunit/phpunit: ^10.0 || ^11.0 || ^12.0 || ^13.0
Requires (Dev)
- ext-mbstring: *
- ext-simplexml: *
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Comprehensive JSON coverage reporter for PHPUnit. Reports all 5 coverage metrics: Line, Branch, Path, Function, and Class.
Why this package exists
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.
Background
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.
How it works
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
Use Cases
- CI pipelines (custom coverage checks)
- Programmatic analysis (scripts, tooling)
- Frontend dashboards
- Integration with other systems
Supported Versions
| PHPUnit | php-code-coverage | Status |
|---|---|---|
| 10.x | 10.x | ✅ Tested |
| 11.x | 11.x | ✅ Tested |
| 12.x | 12.x | ✅ Tested |
| 13.0.x | 13.x | ✅ Tested |
| 13.1+ | 14.x | ✅ Tested |
See Version Compatibility for detailed test results.
Installation
composer require --dev turkeryildirim/phpunit-json-coverage-report
Configuration
Add 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); missing directories are created --> <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/phpunit
A coverage.json file will be generated in your project root.
Documentation
- 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
License
MIT License - see LICENSE for details.