3

I have a laravel project and I tried to run phpunit to give me a coverage report. I ran the command vendor/bin/phpunit --coverage-html storage/test-output-data/coverage-html and it gave the output:

PHPUnit 8.5.8 by Sebastian Bergmann and contributors.
Error:         No code coverage driver is available

I tried to resolve this situation by doing a sudo pecl install pcov, but running the phpunit still gave the same error above.

I noticed that I have the file /usr/lib/php/20170718/pcov.so. So I added the line extension=/usr/lib/php/20170718/pcov.so to my /etc/php/7.4/cli/php.ini file. But when I type php -v, I get this error:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/20170718/pcov.so' (tried: /usr/lib/php/20170718/pcov.so (/usr/lib/php/20170718/pcov.so: undefined symbol: _zval_ptr_dtor), /usr/lib/php/20190902//usr/lib/php/20170718/pcov.so.so (/usr/lib/php/20190902//usr/lib/php/20170718/pcov.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP 7.4.11 (cli) (built: Oct 10 2020 19:44:50) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.11, Copyright (c), by Zend Technologies

I also have a folder called /usr/lib/php/20190902 but it does not have a pcov.so file.

I also tried doing a sudo pecl install xdebug, but I run into similar errors as above where phpunit says there's no driver and typing php -v says some global variable is missing similar to the pcov issue.

What am I doing wrong?

3
  • 1
    /usr/lib/php/20170718/pcov.so -- this is for PHP v7.2 (based on 20170718 part) while you are trying to use it in PHP 7.4. Yeah -- just get the right version of Xdebug or PCOV for your PHP 7.4 (P.S. for PHP 7.4 the API version will be 20190902) Commented Oct 16, 2020 at 11:24
  • 1
    Try this solution to "switch" / install extensions via PECL for specific PHP version (7.4 instead of your current 7.2): stackoverflow.com/a/54594604/783119 Commented Oct 16, 2020 at 11:32
  • @lazyone thank you, doing a sudo pecl -d php_suffix=7.4 install pcov properly installed pcov for me. And now PHPUnit is able to generate the coverage reports. Commented Oct 16, 2020 at 14:09

3 Answers 3

3

I noticed that I have the file /usr/lib/php/20170718/pcov.so. So I added the line extension=/usr/lib/php/20170718/pcov.so to my /etc/php/7.4/cli/php.ini file.

This file is for PHP 7.2 (based on 20170718 part) while you are trying to use it in PHP 7.4.

You need to get the right version of Xdebug (or PCOV) for your PHP 7.4. (NOTE: for PHP 7.4 the API version (and the right folder in the path) will be 20190902.)

Try this solution from the following answer to switch / install extensions via PECL for specific PHP version (7.4 instead of your current 7.2): https://stackoverflow.com/a/54594604/783119

sudo pecl -d php_suffix=7.4 install <package-name>
Sign up to request clarification or add additional context in comments.

Comments

3

This has nothing to do with PHPUnit. You have a problem with your PHP environment: PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20170718/pcov.so' (tried: /usr/lib/php/20170718/pcov.so (/usr/lib/php/20170718/pcov.so: undefined symbol: _zval_ptr_dtor), /usr/lib/php/20190902//usr/lib/php/20170718/pcov.so.so (/usr/lib/php/20190902//usr/lib/php/20170718/pcov.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

Comments

1

You just need to install xdebug, so the coverage knows how to run.

For example, for PHP 7.1, it's this package:

sudo apt install php7.1-xdebug

Just fixed it today for my scenario. In your case, just change the PHP version to:

sudo apt install php7.4-xdebug

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.