告诉我花括号何时应被视为“覆盖”或“未覆盖”的经验法则是什么?
有一个"Edge Cases" section in the phpunit documentation http://www.phpunit.de/manual/current/en/code-coverage-analysis.html#code-coverage-analysis.edge-cases但这显然并不完整,正如我在过去的观看日中了解到的那样:)
我个人从未见过你的第二个例子失败了。我也无法重现它:我找不到无法解决问题的 PHP/xDebug/PHPUnit 组合。 (转载如下)
您展示的另一个案例也是如此。尽管如此,我可以测试两个被检测为“不可执行/不可访问”的右大括号,就像人们所期望的那样。
因此,对于这两种情况,不需要 //@codeCoverageIgnore 或 //@codeCoverageIgnore[Start|End] 。
正如@Derick 在评论中建议的那样,进行任何进一步的分析都需要整个文件。
复制
<?php
class Foo
{
public $myProperty;
public function myMethod()
{
$this->myProperty = '1';
}
}
<?php
require __DIR__ . '/closingBrace.php';
class FooTest extends PHPUnit_Framework_TestCase {
public function testMyMethod() {
$x = new Foo();
$x->myMethod();
}
}
Running phpunit --coverage-text fooTest.php
Code Coverage Report
2012-01-12 10:17:32
Summary:
Classes: 100.00% (1/1)
Methods: 100.00% (1/1)
Lines: 100.00% (2/2)
这仅标志着$this->myProperty = '1';
它将右大括号作为可执行文件。