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. Integrate it in test runs to start/stop coverage collection, filter included files, and generate reports such as OpenClover, including from serialized coverage data.

View on GitHub
Deep Wiki
Context7

Library that provides collection, processing, and rendering functionality for PHP code coverage information.

Frequently asked questions about Php Code Coverage
How do I integrate php-code-coverage into Laravel’s PHPUnit tests?
Add it as a dev dependency via `composer require --dev phpunit/php-code-coverage`, then configure PHPUnit’s `clover` or `coverage` flags in `phpunit.xml`. Laravel’s default PHPUnit setup already supports it—no extra Laravel-specific config is needed.
Does this package work with PestPHP for Laravel testing?
Yes, it’s fully compatible with PestPHP. Use the `--coverage` flag in Pest commands (e.g., `pest --coverage`) to generate reports. The package’s fixes for closures and case statements also improve Pest’s coverage accuracy in Laravel projects.
What Laravel versions and PHP versions are supported?
The package has no Laravel-specific version requirements but works seamlessly with Laravel 9+, 10+, and 11+. It requires PHP 8.0+ (or PHP 7.4+ for older versions). Always pin to `^9.0` or later for stability.
How do I filter coverage to exclude Laravel vendor files?
Use the `Filter` class to exclude vendor paths. For example, `$filter->excludeFiles([__DIR__.'/vendor']);`. Laravel’s default test setup often auto-excludes `vendor/`—check your `phpunit.xml` for `<filter>` configurations.
Will this slow down my Laravel CI/CD pipeline?
Yes, coverage collection adds ~20–50% overhead. Mitigate this by running coverage only in CI (e.g., `phpunit --coverage --group coverage`) or using parallel testing with PestPHP (`pest --parallel`). Avoid running it in production.
How do I generate OpenClover reports for SonarQube in Laravel?
Use the `ReportFacade` to render OpenClover XML. Example: `ReportFacade::fromObject($coverage)->renderOpenClover('/tmp/clover.xml');`. Laravel CI tools like GitHub Actions can then upload this file to SonarQube using standard plugins.
Does this package fix coverage issues with Laravel’s route closures or middleware?
Yes, version 14.1.8 improves coverage for closures (e.g., `Route::get(fn() => ...)`) and `case` statements. Re-run coverage after updating if your tests use these patterns—it may reveal previously missed branches in Laravel’s routing logic.
Can I use PCOV instead of Xdebug for Laravel coverage?
Yes, the package supports both. Configure PCOV in `php.ini` (`extension=pcov.so`) and select it via `DriverSelector::forLineCoverage()`. PCOV is lighter than Xdebug but may miss some edge cases—test thoroughly in your Laravel environment.
How do I serialize coverage data for later analysis in Laravel?
Use the `Serializer` class to save coverage data: `$serializer->serialize($coverage, '/tmp/coverage.php');`. Later, deserialize with `Unserializer` and regenerate reports. This is useful for distributed CI setups or offline analysis.
What alternatives exist for Laravel coverage if I don’t want to use php-code-coverage?
PestPHP has built-in coverage support (`--coverage`), and tools like `infection` (mutation testing) or `paratest` (parallel testing) offer alternatives. However, php-code-coverage remains the most flexible for custom reporting (e.g., OpenClover, HTML) and edge-case fixes.
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai