PHPUnit whitelists and blacklist seem to be ignored

I am setting up PHPUnit for a project that is structured as follows:

- build - src - service # PHP source code files here - tests - php - unit # PHP unit tests here - bootstrap.php # PHP unit tests here - services - MyTest.php - ... - vendor 

I created the following PHPUnit configuration file, which is located in the root of the project:

 <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.4/phpunit.xsd" bootstrap="tests/php/unit/bootstrap.php" verbose="true"> <testsuites> <testsuite name="services"> <directory>tests/php/unit/services</directory> </testsuite> </testsuites> <filter> <whitelist> <directory>src/service</directory> </whitelist> </filter> <logging> <log type="coverage-html" target="build/php/coverage"/> <log type="coverage-clover" target="build/php/coverage.xml"/> <log type="junit" target="build/php/test-results.xml"/> </logging> </phpunit> 

I want to use a whitelist so that PHPUnit does not test PHP files outside the project, for example, in the vendor directory ... But, looking at the code coverage report, it seems that the whitelist is not taken into account:

Code coverage

As can be seen from the capture, tests and vendor written as covered by 0%, although they should not be analyzed, since they do not belong to the white list. The "2% files" of the src directory correspond to the only test I wrote, so the code coverage seems to be correct for this.

How can I make src/service really the only directory to parse to calculate code coverage?

I am using PHP 5.4.3 and PHPUnit 4.4.5.

+7
php phpunit whitelist
source share
1 answer

The problem is resolved. The fact that I do not use the processUncoveredFilesFromWhitelist parameter implies that, unless I explicitly whitelist directories, they will not be analyzed based on coverage. Therefore, in my case, the blacklist seems useless, since only items in the white list are taken into account; and if I want to exclude subdirectories of this whitelist, I can use a tag.

+6
source share

All Articles