【问题标题】:PHPUnit's whitelist and blacklist seem to be ignoredPHPUnit的白名单和黑名单似乎被忽略了
【发布时间】: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目录中的那些...但是查看代码覆盖率报告,似乎白名单不是考虑到:

从捕获中可以看出,testsvendor 的覆盖率为 0%,尽管它们不应该被分析,因为它们不属于白名单。 src 目录的 '2% files' 对应于我编写的唯一测试,因此代码覆盖率似乎是正确的。

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

我使用 PHP 5.4.3 和 PHPUnit 4.4.5。

【问题讨论】:

  • vendor 中的文件报告为0% 意味着它们被忽略。 IDE 是否报告其中任何一个覆盖的行超过 0% 行?我猜不是。

标签: php phpunit whitelist


【解决方案1】:

问题解决了。我不使用 processUncoveredFilesFromWhitelist 参数这一事实意味着,除非我明确地将目录放入白名单,否则它们不会被覆盖分析。因此,在我的情况下,黑名单似乎没有用,因为只考虑了白名单中的项目;如果我想排除这个白名单的子目录,我可以使用标签。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-28
    • 2016-09-30
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    • 2012-04-22
    相关资源
    最近更新 更多