Ticket #256 (new enhancement)

Opened 2 months ago

Last modified 1 month ago

Ignore dead code in code coverage

Reported by: Takkie Assigned to: mrook
Priority: minor Milestone: 2.3.1
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

CoverageMerger.php.patch (501 bytes) - added by Joey Mazzarelli <mazzarelli@gmail.com> on 07/02/08 16:52:10.
Patch for CoverageMerger.php
CoverageSetupTask.php.patch (357 bytes) - added by Joey Mazzarelli <mazzarelli@gmail.com> on 07/02/08 16:52:41.
Patch for CoverageSetupTask.php

Change History

07/02/08 16:52:10 changed by Joey Mazzarelli <mazzarelli@gmail.com>

  • attachment CoverageMerger.php.patch added.

Patch for CoverageMerger.php

07/02/08 16:52:41 changed by Joey Mazzarelli <mazzarelli@gmail.com>

  • attachment CoverageSetupTask.php.patch added.

Patch for CoverageSetupTask.php

(follow-up: ↓ 2 ) 07/02/08 16:56:24 changed by Joey Mazzarelli <mazzarelli@gmail.com>

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.

(in reply to: ↑ 1 ) 07/07/08 07:29:50 changed 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.


Add/Change #256 (Ignore dead code in code coverage)