2

We are struggling to get desired results from the coverage report using phpunit.

Previously, we were only capturing code coverage for files that had unit tests associated with them (I believe this is the default setting When the whitelist is empty).

Now we would like to have a coverage report which includes our already tested files, along with one or two specific directories (which have files with 0% coverage). This should give us more realistic statistics.

We have used an xml configuration file to try and accomplish this:

<filter>
    <whitelist processUncoveredFilesFromWhitelist="true">
        <directory suffix=".php">php/lib/</directory>
    </whitelist>
    <blacklist>
        <directory suffix=".php">/usr/share/php/SymfonyComponents/YAML</directory>
    </blacklist>
</filter>

However, this config now only includes coverage report for that one specified directory in our whitelist. It is not capturing coverage for other files which we have written unit tests for.

How do I achieve a code coverage configuration which captures coverage for:

1) all files that already have unit tests associated with them

2) Other configurable directories

2 Answers 2

1

The following is an example of what we use to cover directories not covered by our tests. The section covers the application. We have different file extensions so the directory suffix examples are included for you as well.

<!-- Add files not covered with tests into Code Coverage Analysis -->
<filter>
    <whitelist addUncoveredFilesFromWhitelist="true">
        <directory suffix=".class">.</directory>
        <directory suffix=".fn">.</directory>
        <directory suffix=".php">lib/UTIL</directory>

        <exclude>
            <file>lib/UTIL/AJAX.class</file>
            <file>lib/UTIL/GetDump.fn</file>
            <directory>ExternalLibraries</directory>
        </exclude>
    </whitelist>
</filter>
Sign up to request clarification or add additional context in comments.

Comments

0

IIRC, PHPUnit uses <whitelist> if it presents, if not, then it uses <blacklist>. Try removing <whitelist> at all.

1 Comment

Removing whitelist will mean that we won't get any coverage reporting for our php/lib/ directory. Is there a way to get the best of both worlds?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.