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 ...
There are certainly many ways to answer the question, while we're finding out, I leave some first drafts.
Your Phpunit XML configuration:
is with the
pathCoverage
attributestrue
value.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:
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:
otherwise any of the two options works with PHP, configure the run job appropriately.
However if you are not concerned about xdebug but pcov
The warning about the xdebug configuration tells a different story: xdebug and pcov are exclusive and
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.-d extension=<extension>
[ini.extension]Some extensions like xdebug need to be loaded as a zend extension:
-d zend_extension=<zend_extension>
[ini.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:
php.ini
file(s) that ship with your PHP distribution