RSSAmplifier

susi.dev · Nov 20, 2021

Generate Code Coverage with native PHP Debugger (no Xdebug required)

0
Sign in to vote or save

Susanne Moog · susi.dev

phpdbg is the native PHP debugger and can generate code coverage without Xdebug. This is handy for CI and often faster to boot than enabling Xdebug.

Basic usage

phpdbg -qrr ./vendor/bin/phpunit --coverage-html build/coverage
  • -qrr runs phpunit through phpdbg in quiet mode
  • The coverage report will be written to build/coverage/index.html

Coverage formats

# HTML report
phpdbg -qrr ./vendor/bin/phpunit --coverage-html build/coverage

# Clover XML for CI (GitLab/GitHub integrations)
phpdbg -qrr ./vendor/bin/phpunit --coverage-clover build/coverage.xml

With DDEV/Docker

ddev exec phpdbg -qrr ./vendor/bin/phpunit --coverage-clover build/coverage.xml

Add a Composer script:

{
  "scripts": {
    "test:coverage": "phpdbg -qrr ./vendor/bin/phpunit --coverage-html build/coverage"
  }
}

PhpStorm integration

In PhpStorm, you can still run PHPUnit with coverage by selecting the CLI interpreter that supports phpdbg (or configure the DDEV/Docker remote interpreter) and checking “Coverage”.

Notes

  • No need to enable Xdebug just for coverage
  • Great for CI environments
  • For profiling or step debugging, use Xdebug

Read the original on susi.dev

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.