CodeCoverage with PHPunit not generating

2019-07-18 03:39发布

问题:

PHPunit 3.7.1 PHP 5.3.14 Windows 7

Using cmd I "cd" into the dir where phpunit.xml lives and run

phpunit -c phpunit.xml

but that dosen't generate any code coverage.

phpunit.xml:

<phpunit
bootstrap="./bootstrap.php"
verbose="true"
>
    <testsuites>
        <testsuite name="Test Suite">
            <directory suffix=".php">./Base/src/</directory>
            <filter>
                <whitelist addUncoveredFilesFromWhitelist="true">
                    <directory suffix=".php">../src</directory>
                    <exclude>
                        <directory suffix=".php">../../vendor</directory>
                    </exclude>
                </whitelist>
            </filter>
            <logging>
                <log type="coverage-html" target="./CodeCoverage/"/>
            </logging>
        </testsuite>
    </testsuites>
</phpunit>

when I run

phpunit -c phpunit.xml --coverage-html CodeCoverage

that works just fine, except nothing in the filter seem to work.

What am I doing wrong here?

回答1:

I don't know if phpunit supports the definition of filter and logging inside a testsuite. Defining it all on it's own should work:

<phpunit
bootstrap="./bootstrap.php"
verbose="true">
    <testsuites>
        <testsuite name="Test Suite">
            <directory suffix=".php">./Base/src/</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist addUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">../src</directory>
            <exclude>
                <directory suffix=".php">../../vendor</directory>
            </exclude>
        </whitelist>
    </filter>
    <logging>
        <log type="coverage-html" target="./CodeCoverage/"/>
    </logging>
</phpunit>