I am setting up PHPUnit on a project which is structured the following way :
- 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 at 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 in order PHPUnit not to test out-of-project PHP files, such as those in the vendor
directory... But looking at the code coverage report, it seems that the whitelist is not taken into account :
As seen on the capture the tests
and vendor
are written to be 0% covered, although they are not supposed to be analyzed as they don't belong to the whitelist. The '2% files' of the src
directory corresponds to the only test that I have written, so the code coverage seems to be correct for this one.
How can I make the src/service
really be the only directory to be analyzed to calculate the code coverage ?
I use PHP 5.4.3 and PHPUnit 4.4.5.