简体   繁体   中英

Why is PHPUnit + pcov not generating code coverage stats?

I had PHPUnit configured to generate code coverage statistics using XDebug. Seeing that PCOV was faster, I disabled xdebug.so and installed pcov.so .

Now, whenever I run my unit tests, the generated coverage report has no numbers or names or anything: 在此处输入图像描述

Here's the script that calls phpunit:

#!/bin/bash
script_dir=$(dirname $0);

php $script_dir/phpunit.phar --coverage-html ../../public/coverage

Here is my phpunit.xml, which was unchanged in the process of moving from XDebug to PCOV:

<?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="bootstrap.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>tests</directory>
        </testsuite>
    </testsuites>

    <coverage cacheDirectory=".phpunit.cache/code-coverage"
              processUncoveredFiles="true">
        <include>
            <directory suffix=".php">../../app/</directory>
        </include>
        <exclude>
            <directory suffix=".php">../../app/config/</directory>
            <directory suffix=".php">../../app/libs/</directory>
            <directory suffix=".php">../../app/views/</directory>
        </exclude>
    </coverage>
</phpunit>

Here is the output:

PHPUnit 9.5.6 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.3.11 with PCOV 1.0.9
Configuration: /path/to/phpunit.xml

..............                                                    14 / 14 (100%)

Time: 00:00.751, Memory: 20.00 MB

OK (14 tests, 38 assertions)

Generating code coverage report in HTML format ... done [00:00.074]

PHP version: 7.3.11
PHPUnit version: 9.5.6
PCOV version: 1.09

Is there some additional configuration that needs to be done for PCOV or for PHPUnit for the coverage report to be useful?

For those who might be still looking for a solution:

You gotta set pcov.directory config to your code base path (eg /var/www/html/app), either as a command:

php -d pcov.directory=/var/www/html/app vendor/bin/phpunit --coverage-html=coverage

or in a PHP.ini file (eg php.ini or pcov.ini)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM