Skip to content

Commit

Permalink
Calculate percentages for tested traits correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Aug 7, 2012
1 parent cfd577b commit 3f68939
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 9 deletions.
8 changes: 4 additions & 4 deletions PHP/CodeCoverage/Report/HTML/Renderer/Directory.php
Expand Up @@ -100,8 +100,8 @@ public function render(PHP_CodeCoverage_Report_Node_Directory $node, $file, $tit
protected function renderItem(PHP_CodeCoverage_Report_Node $item, $total = FALSE)
{
$data = array(
'numClasses' => $item->getNumClasses(),
'numTestedClasses' => $item->getNumTestedClasses(),
'numClasses' => $item->getNumClassesAndTraits(),
'numTestedClasses' => $item->getNumTestedClassesAndTraits(),
'numMethods' => $item->getNumMethods(),
'numTestedMethods' => $item->getNumTestedMethods(),
'linesExecutedPercent' => $item->getLineExecutedPercent(FALSE),
Expand All @@ -110,8 +110,8 @@ protected function renderItem(PHP_CodeCoverage_Report_Node $item, $total = FALSE
'numExecutableLines' => $item->getNumExecutableLines(),
'testedMethodsPercent' => $item->getTestedMethodsPercent(FALSE),
'testedMethodsPercentAsString' => $item->getTestedMethodsPercent(),
'testedClassesPercent' => $item->getTestedClassesPercent(FALSE),
'testedClassesPercentAsString' => $item->getTestedClassesPercent()
'testedClassesPercent' => $item->getTestedClassesAndTraitsPercent(FALSE),
'testedClassesPercentAsString' => $item->getTestedClassesAndTraitsPercent()
);

if ($total) {
Expand Down
4 changes: 2 additions & 2 deletions PHP/CodeCoverage/Report/HTML/Renderer/File.php
Expand Up @@ -159,8 +159,8 @@ protected function renderItems(PHP_CodeCoverage_Report_Node_File $node)
array(
'itemClass' => 'coverDirectory',
'name' => 'Total',
'numClasses' => $node->getNumClasses() + $node->getNumTraits(),
'numTestedClasses' => $node->getNumTestedClasses() + $node->getNumTestedTraits(),
'numClasses' => $node->getNumClassesAndTraits(),
'numTestedClasses' => $node->getNumTestedClassesAndTraits(),
'numMethods' => $node->getNumMethods(),
'numTestedMethods' => $node->getNumTestedMethods(),
'linesExecutedPercent' => $node->getLineExecutedPercent(FALSE),
Expand Down
Expand Up @@ -53,7 +53,7 @@
<td class="tableHead">&nbsp;</td>
<td class="tableHead" colspan="3">Lines</td>
<td class="tableHead" colspan="3">Functions / Methods</td>
<td class="tableHead" colspan="3">Classes</td>
<td class="tableHead" colspan="3">Classes / Traits</td>
</tr>
{items}
</table>
Expand Down
Expand Up @@ -49,7 +49,7 @@
</tr>
<tr>
<td class="tableHead">&nbsp;</td>
<td class="tableHead" colspan="3">Classes</td>
<td class="tableHead" colspan="3">Classes / Traits</td>
<td class="tableHead" colspan="4">Functions / Methods</td>
<td class="tableHead" colspan="3">Lines</td>
</tr>
Expand Down
Expand Up @@ -46,7 +46,7 @@
</tr>
<tr>
<td class="tableHead">&nbsp;</td>
<td class="tableHead" colspan="3">Classes</td>
<td class="tableHead" colspan="3">Classes / Traits</td>
<td class="tableHead" colspan="3">Functions / Methods</td>
<td class="tableHead" colspan="3">Lines</td>
</tr>
Expand Down
38 changes: 38 additions & 0 deletions PHP/CodeCoverage/Report/Node.php
Expand Up @@ -202,6 +202,22 @@ public function getTestedTraitsPercent($asString = TRUE)
);
}

/**
* Returns the percentage of traits that has been tested.
*
* @param boolean $asString
* @return integer
* @since Method available since Release 1.2.0
*/
public function getTestedClassesAndTraitsPercent($asString = TRUE)
{
return PHP_CodeCoverage_Util::percent(
$this->getNumTestedClassesAndTraits(),
$this->getNumClassesAndTraits(),
$asString
);
}

/**
* Returns the percentage of methods that has been tested.
*
Expand Down Expand Up @@ -232,6 +248,28 @@ public function getLineExecutedPercent($asString = TRUE)
);
}

/**
* Returns the number of classes and traits.
*
* @return integer
* @since Method available since Release 1.2.0
*/
public function getNumClassesAndTraits()
{
return $this->getNumClasses() + $this->getNumTraits();
}

/**
* Returns the number of tested classes and traits.
*
* @return integer
* @since Method available since Release 1.2.0
*/
public function getNumTestedClassesAndTraits()
{
return $this->getNumTestedClasses() + $this->getNumTestedTraits();
}

/**
* Returns the classes of this node.
*
Expand Down

0 comments on commit 3f68939

Please sign in to comment.