- 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.