PHPUnit. Error: No code coverage driver is available. (having xdebug installed)

PHPUnit. Error: No code coverage driver is available. (having xdebug installed)

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

PHPUnit. Error: No code coverage driver is available. (having xdebug installed)

When running PHPUnit tests, you might encounter the error Error: No code coverage driver is available. This often happens when you have Xdebug installed but PHPUnit cannot locate or initialize the coverage driver. While Xdebug is a powerful tool for debugging and profiling, it doesn't automatically enable code coverage reporting in every context, especially within IDEs like NetBeans that invoke PHPUnit via specific wrappers.

In the case of a Windows environment using WAMP, PHP 7, and NetBeans 8.1, this issue arises because the test runner invoked by NetBeans does not have access to the Xdebug extension loaded in your Apache or CLI php.ini. The error message appears even though the tests run successfully (e.g., "OK, but incomplete, skipped, or risky tests!"), indicating that PHPUnit completed the execution but failed to generate coverage data.

How Code Coverage Works with Xdebug

Code coverage reporting relies on the PHP extension being loaded and configured correctly. When PHPUnit runs with the --coverage-clover flag, it looks for an active coverage driver. By default, Xdebug acts as this driver. However, if the CLI version of PHP used by PHPUnit doesn't have Xdebug enabled, or if the environment variables don't match, PHPUnit falls back to a generic driver that may not be available on your system.

The key here is ensuring that the phpunit.bat script (or equivalent) is invoking the correct PHP binary with the correct extensions loaded. In many setups, especially on Windows with WAMP, the Apache configuration (httpd.conf) and the CLI configuration (php.ini) are separate files. If Xdebug is only enabled in the Apache config, the CLI PHPUnit runner won't see it.

Checking Your PHP Configuration

To resolve this, you need to confirm that Xdebug is loaded in the context of the CLI tool. Open your php.ini file for the CLI (often located in C:\wamp\bin\php\php7.0.1\php.ini) and verify the following:

[xdebug]
zend_extension="C:/wamp/bin/php/php7.0.1/zend_ext/php_xdebug-2.4.0rc3-7.0-vc14.dll"
xdebug.remote_enable = off
xdebug.profiler_enable = off
xdebug.profiler_enable_trigger = Off
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir ="C:/wamp/tmp"
xdebug.show_local_vars=0

Note that xdebug.remote_enable is set to off, which is appropriate for unit testing environments. However, the critical line is the zend_extension directive. Ensure that this path is correct and that the extension file exists at that location. You can verify this by running:

php -m | findstr xdebug

If Xdebug is not listed in the output, you need to reload your PHP configuration or restart WAMP.

NetBeans-Specific Considerations

NetBeans often invokes PHPUnit through a custom suite file (NetBeansSuite.php) and expects certain output formats. The error occurs because the wrapper script passed to PHPUnit does not forward the necessary environment variables or paths to locate Xdebug.

In some cases, simply adding the following to your php.ini may help:

xdebug.coverage_enable = On

This ensures that Xdebug explicitly enables coverage collection when available. Additionally, make sure that the phpunit.bat file in your project directory is calling the correct PHP executable. If you're using a custom setup, ensure that the path to the PHP binary includes the extension directories where Xdebug is installed.

Alternative: Using a Different Coverage Driver

If you cannot get Xdebug working in the CLI context, consider using an alternative coverage driver like PCOV or Xdebug's built-in profiler mode (though less common for unit tests). However, sticking with Xdebug is generally preferred due to its integration with IDEs and detailed profiling capabilities.

To summarize, resolving the "No code coverage driver is available" error involves ensuring that Xdebug is properly loaded in the CLI environment, not just the web server. Double-check your php.ini, restart your development stack, and confirm that the PHPUnit runner has access to the required extensions. Once configured correctly, NetBeans should display code coverage without issues.

Our network