Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code coverage for lines following methods that always throw exceptions

I understand that 100% code coverage is just a goal to shoot for, but it's annoying to have a line containing a closing brace counted as not covered because it follows a method call whose sole purpose is to throw an exception. Here's a simple example from my base test case class to demonstrate:

function checkForSkipAllTests() {
    if (self::$_skipAllTests) {
        self::markTestSkipped();   // [1] always throws an exception
    }                              // [2] shown as executable but not covered
}

Since [1] always exits the method, line [2] is not actually reachable. Is there any way to tell Xdebug this by annotating the markTestSkipped() method itself?

like image 615
David Harkness Avatar asked Dec 28 '22 11:12

David Harkness


1 Answers

Your pull request got merged so starting with php-code-coverage 1.1.2, which should come around rather soon (with PHPUnit 3.6.3 or 3.6.4) one will be able to write:

private static function checkForSkipAllTests() {
    if (self::$_skipAllTests) {
        self::markTestSkipped();
    } // @codeCoverageIgnore
}

Also in the further away future when xDebug will be able to provide 'Conditionals' coverage i think i remember discussion about making the whole issue going away with that refactoring as the closing brace will just count as 'covered' when the last statement in a function terminates the function... But I might be wrong on that

like image 144
edorian Avatar answered Jan 13 '23 12:01

edorian