gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 12:54:11 27 4
gpt4 key购买 nike

我正在一个结构如下的项目上设置 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 目录中的文件...但是查看代码覆盖率报告,似乎不考虑白名单:

Code coverage

正如在捕获中看到的,testsvendor 被编写为 0% 覆盖,尽管它们不应该被分析,因为它们不属于白名单。 src 目录的“2% files”对应于我编写的唯一测试,因此代码覆盖对于这个测试似乎是正确的。

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

我使用 PHP 5.4.3 和 PHPUnit 4.4.5。

最佳答案

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

关于PHPUnit的白名单和黑名单似乎被忽略了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29675798/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com