PHPUnit的白名单和黑名单似乎被忽略了

Bru*_*rel 7 php phpunit whitelist

我在一个项目上设置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
Run Code Online (Sandbox Code Playgroud)

我创建了以下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>
Run Code Online (Sandbox Code Playgroud)

我想使用白名单,以便PHPUnit不测试项目外的PHP文件,例如vendor目录中的那些......但是看一下代码覆盖率报告,似乎没有考虑白名单:

代码覆盖率

正如在捕获中所看到的那样tests,vendor被写为0%被覆盖,尽管它们不应被分析,因为它们不属于白名单.目录的"2%文件" src对应于我编写的唯一测试,因此代码覆盖率似乎正确.

如何才能src/service真正成为唯一要分析的目录以计算代码覆盖率?

我使用PHP 5.4.3和PHPUnit 4.4.5.

Bru*_*rel 6

问题解决了.我不使用processUncoveredFilesFromWhitelist参数的事实暗示,除非我明确地将目录放在白名单中,否则它们将不会被覆盖分析.所以在我的情况下,黑名单似乎没用,因为只考虑白名单中的项目; 如果我想要排除此白名单的子目录,我可以使用该标记.