![](/img/trans.png)
[英]How to get Netbeans PHPUnit code coverage working on Windows?
[英]How to exclude files / code blocks from code coverage with Netbeans / PHPStorm / PHPUnit integration
要求:
如何:
忽略方法代码块:
/**
* @codeCoverageIgnore
*/
function functionToBeIgnored() {
// function implementation
}
忽略类代码块:
/**
* @codeCoverageIgnore
*/
class Foo {
// class implementation
}
正如@david-harkness 所说,忽略个别行:
// @codeCoverageIgnoreStart
print 'this line ignored for code coverage';
// @codeCoverageIgnoreEnd
更多信息可以在忽略代码块标题下的PHPUnit 文档中找到。
如果您试图实现 100% 的代码覆盖率,但有一行或多行无法测试,则可以用特殊注释将它们括起来。 它们将在代码覆盖率报告中被忽略。
if (($result = file_get_contents($url)) === false) {
// @codeCoverageIgnoreStart
$this->handleError($url);
// @codeCoverageIgnoreEnd
}
编辑:我发现 Xdebug 通常认为右大括号是可执行的。 :( 如果发生这种情况,请将结束标记移到其下方。
首先确保您拥有最新最好的 phpunit,否则可能会丢失忽略代码。 接下来创建一个phpunit.xml
文件,看起来像这样:
<phpunit colors="true">
<filter>
<blacklist>
<file>file1.php</file>
<file>file2.php</file>
</blacklist>
</filter>
</phpunit>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.