Reputation: 3517
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
Upvotes: 2
Views: 2613
Reputation: 11250
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>
Upvotes: 1
Reputation: 7482
IIRC, PHPUnit uses <whitelist>
if it presents, if not, then it uses <blacklist>
. Try removing <whitelist>
at all.
Upvotes: 0