PHPUnit的白名单和黑名单似乎被忽略了 [英] PHPUnit's whitelist and blacklist seem to be ignored

查看:112
本文介绍了PHPUnit的白名单和黑名单似乎被忽略了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在一个结构如下的项目上设置PHPUnit:

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

我创建了以下PHPUnit配置文件,该文件位于项目的根目录:

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>

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

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 :

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

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.

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

How can I make the src/service really be the only directory to be analyzed to calculate the code coverage ?

我使用PHP 5.4.3和PHPUnit 4.4.5.

I use PHP 5.4.3 and PHPUnit 4.4.5.

推荐答案

问题已解决.我不使用processUncoveredFilesFromWhitelist参数的事实意味着,除非我将目录明确地放入白名单中,否则不会对其进行覆盖率分析.因此在我的情况下,黑名单似乎是无用的,因为只考虑了白名单中的项目;如果要排除此白名单的子目录,可以使用标记.

Problem solved. The fact that I don't use the processUncoveredFilesFromWhitelist parameter implies that except if I explicitly put directories in the whitelist they won't be coverage-analyzed. So in my case a blacklist seems to be useless since only items in the whitelist are taken into account ; and if I want to exclude subdirectories of this whitelist I can use the tag.

这篇关于PHPUnit的白名单和黑名单似乎被忽略了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆