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.

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

报告相同问题?

悬赏问题

  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,