Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Php Code Coverage

Php Code Coverage Laravel Package

phpunit/php-code-coverage

phpunit/php-code-coverage collects, processes, and renders PHP code coverage data. Use it to start/stop coverage during tests, filter included files, and generate reports such as OpenClover XML from live runs or serialized coverage data.

View on GitHub
Deep Wiki
Context7

phpunit/php-code-coverage provides collection, processing, and rendering of PHP code coverage data. It’s the engine behind coverage reporting for PHPUnit-style workflows, letting you record executed lines, apply include/exclude rules, and export results in common report formats.

Use it to capture coverage during test runs or to generate reports later from serialized coverage data, making it suitable for local development and CI pipelines.

  • Collect line coverage via supported drivers with a configurable Filter
  • Include or exclude files to scope coverage to your application code
  • Generate reports through a simple Report Facade API
  • Export to formats such as OpenClover XML for CI/reporting tools
  • Build reports from previously saved (serialized) coverage data
Frequently asked questions about Php Code Coverage
How do I integrate php-code-coverage with Laravel’s built-in PHPUnit testing?
Laravel’s `php artisan test` already uses PHPUnit, which depends on php-code-coverage. Configure coverage in your `phpunit.xml` by adding `<coverage>` tags with `<include>` (e.g., `./app`) and `<exclude>` (e.g., `./vendor`) directives. Run tests with `--coverage-clover` or `--coverage-html` flags for reports.
Can I use this package with Pest instead of PHPUnit for Laravel testing?
Yes, Pest supports coverage via the `--coverage` flag, which internally uses php-code-coverage. Configure Pest’s `phpunit.xml` or run `pest --coverage` to generate reports. Ensure your Pest version aligns with PHPUnit’s coverage drivers for compatibility.
What’s the best way to enforce minimum coverage thresholds in CI for Laravel projects?
Use PHPUnit’s `--min-coverage` flag (e.g., `phpunit --coverage-clover=coverage.clover --min-coverage=80`) in your CI script. For Laravel, add this to your `phpunit.xml` under `<phpunit>` or trigger it via GitHub Actions/GitLab CI. Fail builds if coverage drops below your threshold.
How do I exclude Laravel’s vendor or config files from coverage reports?
Exclude directories in `phpunit.xml` using `<exclude><directory>./vendor</directory></exclude>` or `<exclude><directory>./config</directory></exclude>`. Alternatively, use the `Filter` class programmatically to dynamically exclude paths during coverage collection.
Is php-code-coverage compatible with Laravel 10 and PHP 8.4+?
Yes, php-code-coverage supports PHP 8.4+. Laravel 10 (PHP 8.2+) may require minor adjustments if using older versions (pre-v13.0.0). Test with `composer require phpunit/php-code-coverage:^14.0` for the latest features, including SHA-256 hashing for faster cache keys.
How can I generate OpenClover reports for SonarQube in Laravel?
Run PHPUnit with `--coverage-clover=coverage.clover`, then use the `ReportFacade` to convert the Clover file to OpenClover: `ReportFacade::fromFile('coverage.clover')->renderOpenClover('sonarqube.xml')`. Upload the XML to SonarQube via CI/CD or use GitHub Actions with `sonarsource/sonarqube-scan-action`.
What are the performance implications of php-code-coverage for large Laravel codebases?
XML report generation can add latency for large projects (>10k LOC). Use `--coverage-clover` instead of `--coverage-html` for faster CI runs, or cache coverage data with `CachingSourceAnalyser`. Parallel test execution (e.g., Pest’s `--parallel`) may introduce race conditions; validate with v13.0.2+ fixes.
How do I migrate from deprecated PHP serialization to the new Serializer/Unserializer?
Replace `unserialize(file_get_contents('coverage.php'))` with `Unserializer::unserialize('coverage.php')`. Update custom scripts to use the new `Serializer` class for writing coverage data. This change was introduced in v14.0.0 to improve security and maintainability.
Can I customize coverage reports (e.g., themes, excluded metrics) for Laravel?
Yes, use the `ReportFacade` to customize HTML reports (e.g., dark mode via v14.0.0 palettes). Exclude metrics like methods or branches with `Filter` or PHPUnit’s `<coverage><report><exclude><method/></exclude></report></coverage>`. For OpenClover, validate schema compliance if using experimental features.
What alternatives exist for code coverage in Laravel if php-code-coverage doesn’t fit?
Consider `infection/infection` for mutation testing or `paratestphp/paratest` for parallel test execution with coverage. For simpler setups, `jacoco/jacoco` (Java) or `istanbul.js` (JavaScript) may integrate via CI, but php-code-coverage remains the PHP standard due to its PHPUnit integration and extensibility.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport