1

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

4
  • I thought PHPUnit (running XDebug) told you which lines were executed. I think your array walk lines aren't ever executed that the interpreter sees, likewise } else {. Your co-workers see these same exact lines as covered? Commented Apr 2, 2012 at 4:43
  • ... just read your note more carefully. Bob gets good coverage, you fetch, change your code, and now coverage isn't right? What happens if you fetch clean, and run the tests? Why do you apparantly believe it isn't what you changed? Commented Apr 2, 2012 at 4:53
  • you are all running the same php/xdebug versions? Commented Apr 2, 2012 at 8:00
  • Ira Baxter, I believe it doesn't have anything to do with my changes because if I have no changes at all and pull the latest from the repository it still does not cover those lines, but it does on other developer machines. edorian, I will double check on the php version and xdebug, but I am certain that we are all running the same version of phpunit. Commented Apr 2, 2012 at 12:34

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.