Speed up PHPUnit Code Coverage Analysis

Nicolas Cabot
Dec 19, 2018 · 3 min read
Impact of activating code coverage analysis with default xdebug setup.

1. Whitelist filtering with xdebug

Usage

# dump filter file
$ php vendor/bin/phpunit --dump-xdebug-filter build/xdebug-filter.php
# run the test suite
$ php vendor/bin/phpunit --prepend build/xdebug-filter.php --coverage-html build/coverage-report

Results

Impact of using xdebug filtering.

2. Replacing xdebug with phpdbg

Usage

# run the test suite
$ phpdbg -qrr vendor/bin/phpunit --coverage-html build/coverage-report

Results

Impact of using phpdbg as code coverage data source.

3. Using PCOV as the code coverage driver

Usage

# install the extension
$ pecl install pcov
# run the test suite
$ php -d pcov.enabled=1 vendor/bin/phpunit — coverage-html=var/coverage-report

Results

Impact of using PCOV as code coverage driver.

Nicolas Cabot

Written by

Full-stack web developer, Symfony, Docker, Elasticsearch, NodeJS, React, Vue and Flutter enthusiast. https://github.com/slashfan + https://twitter.com/nicocabot

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade