sebastianbergmann/php-code-coverage — pull request #77 by dharkness (2011-11-09 00:20:11+00:00)
Title: Single lines may be ignored by appending "// @codeCoverageIgnore".

Sometimes you want to ignore a single line for code coverage, especially when calling methods that always throw exceptions such as PHPUnit_Framework_Assert::markTestSkipped(). For example, my base test case has a flag to tell it to skip all future tests due to a catastrophic error in a previous test. Before executing each test it checks for this condition:

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

The first closing brace is marked as not covered because Xdebug doesn't know that it cannot be reached. The old solution is to surround it with ignore comments which makes it unreadable.

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

This commit improves the readability:

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