Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FeatureRequest: Code Coverage, track coverage for missed else statement. #1969

Closed
olegserov opened this issue Nov 26, 2015 · 1 comment
Closed

Comments

@olegserov
Copy link

I have a function.

function testFunction($a) { // This is a very common syntaxes for singleton definition.
   if (!$a) {
        $a = 'empty';
   }

   return $a;
} 

Then, If i do an assert:

$this->assertEquals('empty', testFunction(null));

Everything will be great.
Code coverage will be 100%. But it is not true. Code coverage should track that "else" statement was never executed and highlight this moment.

So, code coverage should track if-elseif-else blocks, and if it founds if-elseif without else and none of the tests executed if-elseif blocks in such matter that they did not stepped inside into this block, it should mark last line of if-elseif as an uncovered and account it into statistics.

I hope I managed to explain it clearly :)

@SvenRtbg
Copy link

There is no "else" statement in your code. And in fact the coverage of 100% is true, because based on the data available to PHPUnit, every line was executed once.

What you want is branch coverage, and it is on the list of things that should be implemented, but not in the way you suggest here. It should be an independent metric, i.e. covered lines are still covered, but branches should get additional information about their decision coverage.

See http://derickrethans.nl/path-branch-coverage.html and http://bugs.xdebug.org/view.php?id=1034 for the status of the required XDebug feature and sebastianbergmann/php-code-coverage#380 for the status of implementation in PHPUnit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants