PHPUnit code coverage does not work and always indicates an incorrect whitelist setting

Ich checked several sources on the net and also for stack overflow, but hasn't been able to solve the problem until now.

Here is my config:

<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.0/phpunit.xsd"
     backupGlobals="false"
     colors="true"
     bootstrap="../../src/test.bootstrap.php"
     convertErrorsToExceptions="true"
     convertNoticesToExceptions="true"
     convertWarningsToExceptions="true"
     processIsolation="false"
     stopOnError="false"
     stopOnFailure="false"
     stopOnIncomplete="false"
     stopOnSkipped="false"
     stopOnRisky="false"
     verbose="true"
>
<!--printerFile="vendor/whatthejeff/emoji-phpunit-resultprinter/src/Emoji/PHPUnit/ResultPrinter.php"-->
<!--printerClass="Emoji\PHPUnit\ResultPrinter"-->
<php>
    <ini name="error_reporting" value="-1" />
    <server name="KERNEL_DIR" value="src/" />
    <env name="BOOTSTRAP_CLEAR_CACHE_ENV" value="testing"/>
</php>

<loggin>
    <log type="coverage-html" target="build/coverage"/>
    <log type="coverage-clover" target="build/logs/clover.xml"/>
    <log type="coverage-crap4j" target="build/logs/crap4j.xml"/>
    <log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
</loggin>

<testsuites>
    <testsuite name="Project Test Suite">
        <directory>src/*/*Bundle/Tests</directory>
        <directory>src/*/Bundle/*Bundle/Tests</directory>
    </testsuite>
</testsuites>

<filter>
    <whitelist>
        <directory>../src</directory>
        <exclude>
            <directory>src/*/*Bundle/Resources</directory>
            <directory>src/*/*Bundle/Tests</directory>
            <directory>src/*/Bundle/*Bundle/Resources</directory>
            <directory>src/*/Bundle/*Bundle/Tests</directory>
        </exclude>
    </whitelist>
</filter>
</phpunit>

      

Due to the limitations of the build server, I need to call phpunit with the following command:

./build/bin/phpunit.phar -c build/config/phpunit.xml --coverage-clover build/logs/clover.xml --coverage-crap4j build/logs/crap4j.xml --coverage-html build/coverage --coverage-xml build/logs/coverage.xml --log-junit build/logs/junit.xml --testdox-html build/testdox/testdox.html  --testdox-xml build/logs/testdox.xml src/ -v

      

Everything works except code coverage. Result:

    PHPUnit 6.1.4 by Sebastian Bergmann and contributors.

    Runtime:       PHP 7.1.5-1+0~20170522123046.25+jessie~1.gbpb8686b with Xdebug 2.6.0-dev
    Configuration: /home/testcase/build-directories/build/config/phpunit.xml
    Error:         Incorrect whitelist config, no code coverage will be generated.

    ..................                                                18 / 18 (100%)

    Time: 945 ms, Memory: 6.00MB

    OK (18 tests, 68 assertions)

      

I'm a little annoyed as the homemade tests work. The Reds message can be ignored (hopefully so) as the Redis server is not fully configured yet.

I am using oh-unit 6.1.4

Please let me know where is the error in my config

+3


source to share


2 answers


Try changing the whitelisting reference in phpunit with this:



<whitelist>
    <directory suffix=".php">./src</directory>
    <exclude>
        <directory>./src/*/*Bundle/Resources</directory>
        <directory>./src/*/*Bundle/Tests</directory>
        <directory>./src/*/Bundle/*Bundle/Resources</directory>
        <directory>./src/*/Bundle/*Bundle/Tests</directory>
    </exclude>
</whitelist>

      

+3


source


The directory specified in the filter/whitelist/directory

XML node refers to the directory containing the phpunit configuration file.



I think you should use ../../src

.

0


source







All Articles