【发布时间】:2015-06-22 22:09:38
【问题描述】:
我正在一个项目中设置 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
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% files' 对应于我编写的唯一测试,因此代码覆盖率似乎是正确的。
如何才能使src/service 真正成为唯一要分析以计算代码覆盖率的目录?
我使用 PHP 5.4.3 和 PHPUnit 4.4.5。
【问题讨论】:
-
将
vendor中的文件报告为0%意味着它们被忽略。 IDE 是否报告其中任何一个覆盖的行超过0%行?我猜不是。