- How do I integrate phpunit-coverage-check into Laravel’s GitHub Actions workflow?
- Add a step after running PHPUnit tests in your GitHub Actions file. Use `composer require robiningelbrecht/phpunit-coverage-check --dev` in a setup step, then run `php vendor/bin/phpunit-coverage-check --min=80 coverage.clover` with your desired threshold. Ensure PHPUnit generates a clover report first with `--coverage-clover=coverage.clover`.
- Does this package work with Laravel’s Pest testing framework?
- Yes, if Pest is configured to generate clover reports via PHPUnit. Add `--coverage-clover=coverage.clover` to your Pest configuration or PHPUnit command, then pass the generated file to `phpunit-coverage-check`. Pest’s underlying PHPUnit compatibility ensures this works seamlessly.
- What happens if my code coverage falls below the threshold in CI?
- The script exits with a non-zero status code (1), causing your CI pipeline to fail. This triggers notifications in GitHub/GitLab and blocks merges. You can customize the exit behavior with `--exit-on-low-coverage` if needed, though the default enforces strict compliance.
- Can I set different coverage thresholds for different parts of my Laravel app?
- No, this package enforces a single global threshold. For granular control, consider alternatives like PHPUnit’s `--min-coverage` with directory-specific configurations or tools like `phpunit-coverage-checker`, which supports per-file thresholds.
- Is this package compatible with PHPUnit 10 (Laravel 10+)?
- Unlikely. The package is unmaintained and may not support newer PHPUnit versions. Test compatibility locally or use a maintained alternative like `phpunit-coverage-checker`, which actively supports PHPUnit 10 and Laravel’s testing ecosystem.
- How do I run this locally before committing to avoid CI failures?
- Add a pre-commit hook using Husky or a custom script in `package.json`. Example: `phpunit --coverage-clover=coverage.clover && php vendor/bin/phpunit-coverage-check --min=80 coverage.clover`. This mimics your CI workflow and catches coverage issues early.
- What are the risks of using an unmaintained package in production?
- The primary risks are compatibility issues with newer PHPUnit/Laravel versions and unpatched security vulnerabilities. Since it’s a CLI tool with minimal dependencies, the impact is limited, but consider forking the repo or switching to `phpunit-coverage-checker` for long-term reliability.
- Can I use this with Laravel Dusk (browser tests) coverage reports?
- Yes, if Dusk generates a clover report via PHPUnit. Ensure your Dusk test command includes `--coverage-clover=coverage.clover`, then pass the output to `phpunit-coverage-check`. Dusk’s PHPUnit integration makes this straightforward.
- How do I configure the package to log warnings instead of failing builds?
- Use the `--exit-on-low-coverage=false` flag to suppress exit codes. The script will still output coverage metrics but won’t fail the build. This is useful for local development or CI environments where warnings are preferred over hard failures.
- What alternatives exist if this package doesn’t meet my needs?
- For Laravel projects, consider PHPUnit’s built-in `--min-coverage` flag or `phpunit-coverage-checker`, which offers per-file thresholds, branch coverage, and active maintenance. Tools like Codecov or SonarQube also provide advanced coverage analytics without requiring clover reports.