Ticket #256 (closed enhancement: fixed)
Ignore dead code in code coverage
| Reported by: | Takkie | Owned by: | mrook |
|---|---|---|---|
| Priority: | minor | Milestone: | 2.4.0RC1 |
| Component: | phing-tasks-phpunit | Version: | 2.3.0 |
| Keywords: | Cc: |
Description
Suppose you've tested the following code:
class Foo
{
public function foo($silent = true)
{
if ($silent) {
return;
}
return 'foo';
}
}
The code coverage generated by Phing will mark the closing brace of the if statement in the foo function as not covered, which will keep the total code coverage below 100%. This closing brace will never be covered because of the return statement right in front of it, but it doesn't contain code either.
When generating a code coverage report using PHPUnit 3.2.21 this line will be marked gray (dead code) and will not have any influence on the total code coverage (coverage will be 100%).
Attachments
Change History
Changed 4 years ago by Joey Mazzarelli <mazzarelli@…>
-
attachment
CoverageMerger.php.patch
added
Changed 4 years ago by Joey Mazzarelli <mazzarelli@…>
-
attachment
CoverageSetupTask.php.patch
added
Patch for CoverageSetupTask.php
comment:1 follow-up: ↓ 2 Changed 4 years ago by Joey Mazzarelli <mazzarelli@…>
I was able to fix the problem with the attached two patches. When ran against the example code you give, it results in the same coverage as the phpunit one does.
I also ran this on a project of the size: Packages: 26 Classes: 261 Methods: 1526 LOC: 38511 Statements: 8013
There were no noticable undesired side effects. I also compared the results on a less-trivial file to the results of PHPUnit, and they also matched.
A better way would be to just use the coverage report generated by phpunit itself, and apply some xsl transformation on that, but in the meantime, this works for my needs.
comment:2 in reply to: ↑ 1 Changed 4 years ago by anonymous
Replying to Joey Mazzarelli <mazzarelli@gmail.com>:
Works like a charm! I agree that using PHPUnit's coverage report would be the preferable solution.

Patch for CoverageMerger.php