Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

PHPUnit says no code coverage driver is available

ErrorNo code coverage driver is available

Short answer

PHPUnit collects coverage through PCOV or Xdebug, and it needs one of them loaded in the PHP binary that runs the tests. With Xdebug the mode must include coverage. Check php -v for the CLI, then enable zend_extension=xdebug in the CLI php.ini and run with XDEBUG_MODE=coverage.

  • Applies to PHPUnit 12, Xdebug 3, PHP 8.3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask the PHP that runs PHPUnit which extensions it has and which ini file it reads. A web server's php.ini is a different file.

    php -v
    php --ini
  2. 2Match what you see, then jump to its fix

    1. 1php -v shows no "with Xdebug" line, although Xdebug works in the browser or is installed for another PHP versionXdebug is not loaded in the command-line PHPFix
    2. 2php -v lists Xdebug, and PHPUnit still reports the missing driverXdebug is loaded but its mode does not include coverageFix
    3. 3Xdebug is not installed, and you only need line coverage in CILine coverage is enough and a lighter driver is wantedFix

What does the error look like?

  • No code coverage driver is available
  • No code coverage driver available

Cause 1 of 3

Xdebug is not loaded in the command-line PHP

1Check

The CLI and the web server often read different php.ini files, so Xdebug can be active for one and missing for the other. php --ini shows the file the CLI reads.

php -v
php --ini

2Fix

Add the extension line to the ini file the CLI reports, or to a file such as 99-xdebug.ini in its scanned directory. If it does not load, use the full path to the extension file.

; in the CLI php.ini (or conf.d/99-xdebug.ini)
zend_extension=xdebug

3Verify

php -v now lists Xdebug and its version.

php -v

Confirmed by xdebug.org

Did this fix it?

Cause 2 of 3

Xdebug is loaded but its mode does not include coverage

1Check

PHPUnit's docs say you have to activate Xdebug's coverage mode. In Xdebug 3 that is the xdebug.mode setting. Ask Xdebug which modes are on.

php -r 'var_dump(xdebug_info("mode"));'

2Fix

Set xdebug.mode to coverage in php.ini, or set it for one run with the XDEBUG_MODE environment variable. The setting only works in php.ini style files, not in .user.ini or .htaccess.

; php.ini or 99-xdebug.ini
xdebug.mode=coverage

# or for a single run
XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text

3Verify

The coverage table prints after the test results, and the driver warning is gone.

XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text

Confirmed by xdebug.org

Did this fix it?

Cause 3 of 3

Line coverage is enough and a lighter driver is wanted

1Check

PHPUnit's coverage guide names PCOV as an alternative to Xdebug. PCOV supports line coverage only; branch and path coverage need Xdebug.

php -m | grep -i -E 'pcov|xdebug'

2Fix

Load either PCOV or Xdebug in the CLI. Use Xdebug if you need path coverage with --path-coverage.

vendor/bin/phpunit --coverage-html build/coverage
vendor/bin/phpunit --path-coverage --coverage-text

3Verify

Open build/coverage/index.html, or read the text table from the second command.

ls build/coverage/index.html

Confirmed by docs.phpunit.de

Did this fix it?

How do I stop it coming back?

  • Run php -v in the same terminal and container that runs the tests, not in a different shell.
  • Keep XDEBUG_MODE=coverage out of the global ini if you debug with Xdebug, and pass it only to the coverage command.
  • In CI, install the coverage driver in the same step as PHP so every job has it.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

Apache returns 403 when a URL contains %3F

a request like /page%3Fname=test is refused while /page?name=test works

Recent Apache httpd blocks a rewrite when the request contains an encoded question mark (%3F) and the rewritten target has a literal ?.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.