duan032225 2012-04-02 04:22
浏览 39
已采纳

PHPUnit代码覆盖率不包括某些行

I'm having a strange issue with PHPUnit. I'm working on a project with a team of developers, all of which must use PHPUnit 3.6.5. For the most part, my PHPUnit works great and yields the same results as on other developers' machines. However, I will occasionally find that a certain line isn't covered on my machine, but is on other developers' machines. Here is a recent scenario:

  • Bob is checking in a new file that he just updated. He made sure the unit test passed for this file and had 95% code coverage. After performing this check, he checks in the file, where it is built and the unit test is run. If the unit test fails on the server, our build goes red and nobody can check in.
  • The server runs the phpunit test and it passes.
  • Other developers, including myself, get the latest from the perforce repository
  • After making my own set of changes, I run all of the phpunit tests for the application, but I notice one of the files does not have enough code coverage. It's the file that Bob just checked in. I check with some of the other developers on my team and the file passes code coverage without any problems for them. When I check the code coverage report, I see the following:

    array_walk(                                                                                            
        $variable1,                                                                                        
        function($val,$key) use(&$variableData, &$variable2)                                            
        {                                                                                                  
            $variableData[$variable2][$key] = 1;                                                               
        }                                                                                                  
    );
    

$variable1,
function($val,$key) use(&$variableData, &$variable2)

These two lines are not covered! I don't understand why my phpunit doesn't want to cover these lines. There must be a setting that I am not aware of that is causing this as I have the same version of PHPUnit as other developers and it passes fine on their machine but not on mine. I'm also seeing the same problem in a statement like this:

    if ($var === 1) {
        echo 'yes';
    } else {
        echo 'nope';
    }

Now, the unit test will cover both conditions, however, it doesn't cover the following line:

} else {

Does this make any sense at all? The strangest part about it is that it works most of the time, but there are a few locations that have this behavior, though there is no pattern to indicate what it causing it. I've had other developers look at this issue on my machine and they are baffled and cannot explain what is causing it. The problem is, since it is failing for me locally, even though I haven't touched Bob's file, it is preventing me from checking in my changes. Has anyone ran into this problem before? I am going to try uninstalling php unit and re-installing it, but other than that, I am at a loss for words. Any help would be greatly appreciated! Here are my specs:

PHPUnit: Version 3.6.5 Operating system: OS X 10.6.8 PHP: PHP 5.3.8-ZS5.5.0 (cli) (built: Aug 24 2011 11:03:29) Zend Debugger: Turned off XDebug: Turned on Zend Optimizer+: off

Regards,

Will

  • 写回答

1条回答 默认 最新

  • douna1895 2013-01-11 06:39
    关注

    Executable and executed lines are reported by xdebug to PHPUnit. Different versions of xdebug may vary in the lines reported as covered.

    If you feel that they are incorrect, provide a simple testcase and open a bug at xdebug's issue tracker.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改