dtnd30892 2015-04-16 13:12
浏览 88
已采纳

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

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>

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 :

Code coverage

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.

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

I use PHP 5.4.3 and PHPUnit 4.4.5.

  • 写回答

1条回答 默认 最新

  • douwu7563 2015-04-17 08:57
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。