我正在为一个按照以下结构组织的项目设置PHPUnit:
- 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
我创建了以下PHPUnit配置文件,位于项目根目录:
我创建了以下PHPUnit配置文件,位于项目根目录:
<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>
我希望使用白名单,以便PHPUnit不测试项目外的PHP文件,例如vendor
目录中的文件...但查看代码覆盖报告,似乎白名单没有被考虑:
如上图所示,尽管它们不属于白名单,但tests
和vendor
都写成了0%覆盖率。而src
目录下的'2% 文件'对应于我编写的唯一测试,因此该测试的代码覆盖率似乎是正确的。
我应该如何使src/service
成为唯一分析以计算代码覆盖率的目录?
我使用PHP 5.4.3和PHPUnit 4.4.5。