简体   繁体   English

使用PHPUnit和XDebug在Generators中提前退出的PHP代码覆盖率

[英]PHP Code Coverage of early exit in Generators with PHPUnit and XDebug

I'm not sure if this is a bug, but I don't seem to be able to get 100% coverage with early exit inside a PHP 5.5 generator. 我不确定这是否是一个错误,但是我似乎无法通过PHP 5.5生成器中的提前退出来获得100%的覆盖率。

For example: 例如:

<?php

function gen($branch = false)
{
    yield;

    if($branch) {
        echo 'branched';
        return;
    } // This line is never covered.
    echo 'did not branch';

}

The closing bracket of the if statement is never covered. if语句的右括号从未涉及。 It's not considered "dead code", it behaves as though you didn't consider the possibility of exiting the if statement. 它不被视为“死代码”,它的行为就好像您没有考虑退出if语句的可能性一样。

I don't want to use an else because, as phpmd would say, "else is never necessary", but I would like to get 100% coverage (as that makes it easy to see if I've missed something in new code without drilling down). 我不想使用else因为,正如phpmd会说的那样,“永远都不需要”,但是我想获得100%的覆盖率(因为这很容易看到我是否在没有新代码的情况下错过了某些内容,向下钻取)。

Has anyone else run into this? 还有其他人遇到吗? Is there a solution? 有解决方案吗?

这是Xdebug中的错误,2.4.0版中已解决

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM