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
Behat Code Coverage

Behat Code Coverage Laravel Package

dvdoug/behat-code-coverage

Behat extension that generates code coverage reports for PHP applications. Wraps PHPUnit’s php-code-coverage library to produce familiar, interoperable reports and integrates coverage generation into your Behat test runs.

View on GitHub
Deep Wiki
Context7

Behat Extension to generate code coverage reports for Behat tests

Frequently asked questions about Behat Code Coverage
How do I install dvdoug/behat-code-coverage for Laravel Behat tests?
Run `composer require --dev dvdoug/behat-code-coverage` and add the extension to your `behat.yml` under `extensions:` with the required configuration (e.g., `reports:` and `filter:`). Ensure Behat 3.7+ and PHP 8.x are installed, as these are prerequisites.
Does this package work with Laravel’s PHPUnit integration?
Yes, it leverages the same `phpunit/php-code-coverage` library (v9–v14) as PHPUnit, so reports are compatible. You can run Behat coverage separately or merge results with PHPUnit’s `--coverage` output using tools like Codecov or SonarQube.
Can I generate Cobertura reports for CI/CD pipelines like GitHub Actions?
Absolutely. Configure `behat.yml` with `reports: [cobertura]` and run `behat --coverage`. The output is CI-friendly and integrates with platforms like Codecov, SonarQube, or GitHub Actions for automated coverage tracking.
Will this slow down my Laravel Behat tests in production?
Coverage collection adds overhead (Xdebug can multiply runtime by 2–5x). Disable it in production by omitting `--coverage` or use PCOV in CI for faster execution. Cache coverage data with `cache: sys_get_temp_dir()` to mitigate performance hits.
How do I exclude Laravel vendor or unit test directories from coverage?
Use the `filter.exclude` option in `behat.yml` to exclude paths like `vendor/`, `tests/Unit/`, or `app/Providers/`. Example: `filter.exclude: ['vendor/', 'tests/Unit/*']`. This aligns coverage with your Behat test scope.
Does this support branch/path coverage for Laravel middleware or service containers?
Yes, but it requires Xdebug or PCOV. Enable it via `coverage: true` in `behat.yml` and configure your environment. Branch coverage is critical for complex Laravel logic like payment flows or authentication middleware.
Can I use this alongside PestPHP for Laravel testing?
Yes, but ensure Behat and Pest tests are mutually exclusive in coverage runs. Run Behat coverage separately (e.g., `behat --coverage`) and aggregate results with PHPUnit/Pest coverage using tools like Codecov or custom scripts.
What Laravel versions and PHP versions are supported?
The package supports Laravel 8.x/9.x/10.x and PHP 8.0+. It’s actively maintained for Symfony 6/7, which Laravel’s dependency stack aligns with. For PHP 7.1+, use older `php-code-coverage` versions if needed.
How do I debug issues with missing or incorrect coverage reports?
Start with `behat --dry-run` to validate `behat.yml` configuration. Check for Xdebug/PCOV conflicts by running `php -v` and `php -m | grep xdebug`. For CI, test reports locally with `behat --coverage --format=html` before pushing.
Are there alternatives to dvdoug/behat-code-coverage for Laravel?
For Behat, this is the most Laravel-friendly option. Alternatives include running PHPUnit’s `--coverage` separately or using `infection/infection` for mutation testing. However, this package uniquely integrates coverage natively into Behat’s workflow without reinventing the coverage logic.
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor