gpt4 book ai didi

php - 代码覆盖率中的接口(interface)和空类

转载 作者:可可西里 更新时间:2023-10-31 23:17:34 24 4
gpt4 key购买 nike

我将 PHPUnit 5.2.9、PHP 5.6.19 和 Xdebug 2.4.0(非 RC)与 netbeans IDE 一起使用。

与任何其他项目一样,我使用接口(interface)和奇怪的空扩展类。由于这些文件不包含可执行代码,为什么它们会列在我的代码覆盖率报告中?不仅如此,它们被列为 0% 覆盖了 0/0 方法。 (如果那是 100% 只是为了减少红色,我会很高兴)

我试过在 phpunit.xml 中排除它们文件:

<whitelist processUncoveredFilesFromWhitelist="false"> // true make no difference
<directory suffix=".php">./Annotation</directory>
<directory suffix=".php">./Cache</directory>
<exclude>
<directory suffix=".php">./*Interface</directory>
<directory suffix=".php">./*/*Interface</directory>
</exclude>
</whitelist>

但似乎 globs (*) 只对目录有效。但是我可以使用 <file>标记并单独排除它们。但是,当一开始就不应该包含这些文件时,需要排除很多文件。

我是做错了什么还是这是标准行为?

最佳答案

您可以尝试如下改进您的排除目录:

<exclude>
<directory suffix="Interface.php">.</directory>
</exclude>

否则,您可以直接在忽略代码中描述的适当注释中标记Blocks of the doc ,如下:

<?php
/**
* @codeCoverageIgnore
*/
interface Foo
{
public function bar();
}

或者您可以将测试用例中接口(interface)类的方法标记为已覆盖,请参阅更多信息in the doc here .例如:

 /**
* @test
* @covers Bar::foo
* @covers BarInterface::foo
*/
public function foo()
{
....
}

希望对你有帮助

关于php - 代码覆盖率中的接口(interface)和空类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35920409/

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