Modify

Ticket #256 (closed enhancement: fixed)

Opened 4 years ago

Last modified 3 years ago

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

CoverageMerger.php.patch Download (501 bytes) - added by Joey Mazzarelli <mazzarelli@…> 4 years ago.
Patch for CoverageMerger.php
CoverageSetupTask.php.patch Download (357 bytes) - added by Joey Mazzarelli <mazzarelli@…> 4 years ago.
Patch for CoverageSetupTask.php

Change History

Changed 4 years ago by Joey Mazzarelli <mazzarelli@…>

Patch for CoverageMerger.php

Changed 4 years ago by Joey Mazzarelli <mazzarelli@…>

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.

comment:3 Changed 3 years ago by mrook

(In [426]) Refs #256 - ignore dead code in coverage

comment:4 Changed 3 years ago by mrook

  • Status changed from new to closed
  • Resolution set to fixed

Applied the patch (with some rework) in r426, thanks!

View

Add a comment

Modify Ticket

Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.