friends-of-phpspec/phpspec-code-coverage
PhpSpec extension that generates code coverage reports (console and HTML) for your specs. Works with Xdebug, phpdbg or pcov and supports multiple PhpSpec/PHP versions, helping you see which parts of your codebase are exercised by tests.
Install via Composer: composer require --dev friends-of-phpspec/phpspec-code-coverage. Ensure PHP ≥ 8.1 (PHP 8.4 now supported) and Xdebug/PCOV is enabled. Enable coverage collection by adding --coverage to your phpspec run command (e.g., vendor/bin/phpspec run --coverage). Reports are generated in build/coverage by default (HTML, Clover, and PHP formats supported). Start with HTML report for quick visual feedback: open build/coverage/index.html in a browser after running tests.
Note: As of v7.0.0, Phpspec 8.0+ is required—older Phpspec versions are no longer supported.
Use --coverage with CLI flags like --coverage-clover=build/coverage.xml for CI integration with tools like SonarQube or GitHub Actions. Combine with Phpspec’s config via phpspec.yml by defining extensions:
extensions:
FriendsOf PhpSpec\CodeCoverage\CodeCoverageExtension: ~
To limit coverage to specific namespaces, use --coverage-filter=src/YourApp/ to avoid including tests or dependencies. For automation, add coverage steps in your CI workflow: run tests → generate report → upload to coverage service.
Note: Phpspec 8.0 compatibility is now enforced—ensure your phpspec/phpspec dependency is ^8.0 (check composer.json and composer.lock).
Coverage requires Xdebug or PCOV; ensure one is installed and enabled—coverage fails silently without it. Phpspec’s --stop-on-failure conflicts with full coverage runs; avoid mixing both. Breaking change: Extension is not auto-registered in Phpspec 8+—you must manually enable it via phpspec.yml. Coverage generation is slow on large suites; consider narrow filtering (--filter + --coverage-filter) during development. Check phpspec.yml for typos in extension class name (FriendsOf PhpSpec has a space—easy to miss). For better CI fidelity, combine with coverage-highlights to flag uncovered new code in PRs.
⚠️ Critical upgrade note: PHP < 8.1 is no longer supported. If your project uses PHP 8.0 or earlier, either upgrade PHP or pin to v6.x (if compatible).
How can I help you explore Laravel packages today?