42
votes

There is an answer for similar question Laravel 5: PHPUnit and no code coverage driver available that works, but i have xdebug installed.

(if this matter I'm using: windows7, netbeans8.1, php7, wamp3)

Displaying code coverage in Netbeans result in:

Error: No code coverage driver is available

, and the output is below:

"C:\wamp\www\treningPHPUnitSymfony2.8\bin\phpunit.bat" "--colors" "--log-junit" "C:\Users\chiny\AppData\Local\Temp\nb-phpunit-log.xml" "--coverage-clover" "C:\Users\chiny\AppData\Local\Temp\nb-phpunit-coverage.xml" "C:\Program Files\NetBeans 8.1\php\phpunit\NetBeansSuite.php" "--" "--run=C:\wamp\www\treningPHPUnitSymfony2.8\src\TreningBundle\Tests\Controller\RabarbarControllerTest.php" PHPUnit 5.3.4 by Sebastian Bergmann and contributors.

Error: No code coverage driver is available

.II 3 / 3 (100%)

Time: 1.13 seconds, Memory: 4.00MB

OK, but incomplete, skipped, or risky tests! Tests: 3, Assertions: 1, Incomplete: 2. Done.](url)

xdebug conf (C:\wamp\bin\apache\apache2.4.17\bin\php.ini):

[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

loaded extensions wamp. loaded extension

(I have netbeans and project directory in same Windows partition)

3
What is php.exe -v telling you? Is xdebug enabled? - Aleksander Wons
C:\Windows\System32>php.exe -v PHP 7.0.1 (cli) (built: Dec 16 2015 13:36:30) ( ZTS ) Copyright (c) 1997-2015 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies - Sruj_2ndAccountForStupidQtions
xdebug as shown in last printscreen in main post is on the list - Sruj_2ndAccountForStupidQtions
xdebug is not enabled in CLI. Enable it and it should work. - Aleksander Wons
thanks, I will google that. I though that if extension is on that list i put meaning it's enable. - Sruj_2ndAccountForStupidQtions

3 Answers

29
votes

There are 2 php.ini files in most Apache/PHP installations and definitely in WAMPServer

To amend the correct php.ini used by PHP in Apache use the menus

wampmanager->PHP->php.ini

But for the php.ini file used by the PHP CLI you have to manually edit

\wamp\bin\php\php{version}\php.ini

the result of a php -v should look like this if XDEBUG is configured in the CLI

php -v
PHP 7.0.6 (cli) (built: Apr 27 2016 14:00:40) ( ZTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans

NOTE

The current WAMPServer 3 is 3.0.4 ADDON upgrades can be found on SourceForge

The latest ADDON PHP Version is PHP7.0.6 also available on SourceForge

See The WampServer Forum to keep up to date with the latest releases of PHP / MYSQL / Apache ADDONS for WAMPServer 3

Also :

You may find that you have to tweek the XDEBUG config parameters in the php.ini to suit your specific needs

10
votes

I've faced this problem with a new installation of PHP 7.1 and this is what I've done to make it work

$ brew install php71-xdebug

$ php -i | grep xdebug // to check if xdebug was installed

$ phpunit

After that it worked. Additionally this is how my phpunit.xml looks like I've needed to whitelist whole structure because it's shared component

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="vendor/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false"
         syntaxCheck="false">
    <testsuites>
        <testsuite name="Tests">
            <directory suffix=".php">./Tests/</directory>
        </testsuite>
    </testsuites>
    <logging>
        <log type="coverage-clover" target="./build/logs/clover.xml"/>
    </logging>
    <filter>
        <whitelist addUncoveredFilesFromWhitelist="true">
            <directory>./</directory>
        </whitelist>
    </filter>
</phpunit>

This solution will work on MacOS only, if you want to make it work on Linux then you need to use applicable package manager like apt-get etc.

3
votes

With the same problem on Debian:

Error: No code coverage driver is available

I fixed it with installing php-xdebug: sudo apt install php-xdebug