1

I use PHP 8.0.5 , PHPUnit 9.5.4, PHPStorm 2021.1.2. When, in my XML configuration file, I use this :

<coverage pathCoverage="true">
  <report>
    <clover outputFile="./coverage.xml"/>
  </report>
</coverage>

(This is only the relevant portion of my file)

...and launch the command 'Run with coverage' from PHPStorm, it does not generate the coverage report.

I have deactivated XDebug. PHPStorm shows me :

Warning: XDEBUG_MODE=coverage or xdebug.mode=coverage has to be set

I do not know why it mentions XDebug as I want to use pcov as I set it in the "Run/Debug Configurations" popin. I try to put the report in another folder, try to generate HTML report instead... launch the command via the terminal ... None of this works. I did not find anything on Google about my issue.

EDIT

I tried with XDebug not loaded at all and this simplified configuration (created with the --generate-configuration parameter) and added the previous code (without the path coverage).

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
         bootstrap="TestBootstrap.php"
         cacheResultFile=".phpunit.cache/test-results"
         executionOrder="depends,defects"
         forceCoversAnnotation="true"
         beStrictAboutCoversAnnotation="true"
         beStrictAboutOutputDuringTests="true"
         beStrictAboutTodoAnnotatedTests="true"
         failOnRisky="true"
         failOnWarning="true"
         verbose="true">
    <testsuites>
        <testsuite name="default">
            <directory suffix="Test.php">./src/BlocksTest.php</directory>
        </testsuite>
    </testsuites>

    <coverage cacheDirectory=".phpunit.cache/code-coverage"
              processUncoveredFiles="true">
        <include>
            <directory suffix=".php">../src</directory>
        </include>
        <report>
            <clover outputFile="./coverage.xml"/>
        </report>
    </coverage>
</phpunit>

It still not works even if the library says :

Generating code coverage report in Clover XML format ...

lionelp
  • 443
  • 1
  • 7
  • 21
  • The warning about XDEBUG_MODE suggests the phpunit code-coverage driver for xdebug is getting loaded. maybe this: https://stackoverflow.com/a/57730778/367456 - ensure xdebug extension is not loaded. The warning also suggests that it is loaded ([via](https://github.com/sebastianbergmann/php-code-coverage/blob/b7e989e280d453f11c3d429162bfe6c901257610/src/Driver/XdebugDriver.php#L43)) – hakre Jun 09 '21 at 22:29
  • I know I have XDebug enabled but I thought disabling code coverage with XDebug was enough ... I will try without it but, XDebug being useful for other purposes that code coverage too, what if we want to use the other features of XDebug? Do we have to switch everytime? – lionelp Jun 11 '21 at 07:28
  • It says "No code coverage driver with path coverage support available" when I disable XDebug and `php -m | grep "pcov"` shows `pcov` as expected. So...what am I missing? – lionelp Jun 11 '21 at 07:37
  • I can imagine this is puzzling, but also hard to say just from that comment. Please find a way you can increment the PHP configuration on the command-line from the very ground up of having no configuration up to running phpunit with the code-coverage of choice (incl. an example for pcov) here: https://stackoverflow.com/a/67912759/367456 - this might give you the insights you're looking for and also help in troubleshooting the issue here. – hakre Jun 11 '21 at 09:53
  • and I do not specifically know what "path coverage support" means in the new warning. No idea if pcov supports it. Maybe this is some configuration in the phpunit XML configuration file? And you can disable it for troubleshooting to find out. – hakre Jun 11 '21 at 09:58

1 Answers1

1

There are certainly many ways to answer the question, while we're finding out, I leave some first drafts.


Your Phpunit XML configuratio:

<coverage pathCoverage="true">
  <report>
    <clover outputFile="./coverage.xml"/>
  </report>
</coverage>

is with the pathCoverage attributes true value.

[In Phpunit 9.5] The pathCoverage Attribute [...] When set to true [..] This requires a code coverage driver that supports path coverage. Path Coverage is currently only implemented by Xdebug.

So you can not have this code coverage report with pcov.

Your Phpunit configuration is incompatible.


When Phpunit (via sebastianbergman/php-code-coverage) shows this warning:

Warning: XDEBUG_MODE=coverage or xdebug.mode=coverage has to be set

it means that it detected the xdebug extension is available but it is not configured in a way to use it, therefore hints which parameters to change.

If you're on the command-line (CLI) replaying the last command with the xdebug mode environment parameter is often most easy for a test-run:

$ XDEBUG_MODE=coverage !! # press enter

otherwise any of the two options works with PHP, configure the run job appropriately.

However if you are not concerned about xdebug but pcov

I do not know why it mentions XDebug as I want to use pcov as I set it [in PhpStorm] in the "Run/Debug Configurations" popin .

the warning about the xdebug configuration tells a different story: xdebug and pcov are exclusive and

Xdebug must not be loaded if you want to use PCOV as the driver for php-code-coverage.

Which means - as the original warning shows that Xdebug is loaded - it has to be unloaded first.

PhpStorm can not unload extensions for the configured PHP version. What it does it that it adds extensions and configuration settings based on your choice.

In PhpStorm similar as it is on the command line (CLI) you can control both environment parameters as well as command line arguments for the PHP executable.

If the existing configuration of the php executable on the system loads already too much, as a last resort you can then disable all extensions first with the -n switch and add extensions as needed.

Some extensions like xdebug need to be loaded as a zend extension:

For a description of the PHP command line options, please see Command line options[DOCS].

For a description of the diverse configuration options, please see either:

  • the commented php.ini file(s) that ship with your PHP distribution
  • the appropriate page in the PHP manual (it also has a List of php.ini directives[DOCS])
  • additional documentation by extension authors, e.g. the Xdebug Homepage often has detailed configuration instructions and covers all ini settings.
hakre
  • 193,403
  • 52
  • 435
  • 836
  • I have seen that the project `phpcov` from Sebastian Bergmann have parameters about path coverage. Isn't that the same driver? https://github.com/sebastianbergmann/phpcov If this is indeed not the same ...how can we have both speed AND path coverage? – lionelp Jun 11 '21 at 11:51
  • I just tested without ` pathCoverage="true"` but the report is still not generated. – lionelp Jun 11 '21 at 11:57
  • @lionelp: reduce the feature set first. Disable `pathCoverage`, e.g. remove that attribute for example. Then rinse and repeat. – hakre Jun 11 '21 at 12:04