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:

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.
php phpunit whitelist
Bruno pérel
source share