PHPUnit says no code coverage driver is available
No code coverage driver is availableShort 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.
Fix it fast
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 --ini2Match what you see, then jump to its fix
- 1
php -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
php -v lists Xdebug, and PHPUnit still reports the missing driverXdebug is loaded but its mode does not include coverageFix - 3
Xdebug is not installed, and you only need line coverage in CILine coverage is enough and a lighter driver is wantedFix
- 1
What does the error look like?
No code coverage driver is availableNo 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 --ini2Fix
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=xdebug3Verify
php -v now lists Xdebug and its version.
php -vConfirmed by xdebug.org
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-text3Verify
The coverage table prints after the test results, and the driver warning is gone.
XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-textConfirmed by xdebug.org
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-text3Verify
Open build/coverage/index.html, or read the text table from the second command.
ls build/coverage/index.htmlConfirmed by docs.phpunit.de
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
Android gets HTML instead of JSON from a PHP API
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
The response body is not JSON.
2 causes, each with a fixBack 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 fixBack end
Apache returns 500 with Premature end of script headers
500 Internal Server Error
Apache ran your script, but the script printed no valid HTTP header before its output.
3 causes, each with a fixBack end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fix