Skip to content

Coverage Thresholds #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion PHP/CodeCoverage/Report/HTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ public function __construct(array $options = array())
$options['generator'] = '';
}

if (!isset($options['methodCoverageThreshold'])) {
$options['methodCoverageThreshold'] = 100;
}

if (!isset($options['classCoverageThreshold'])) {
$options['classCoverageThreshold'] = 100;
}

$this->options = $options;

self::$templatePath = sprintf(
Expand Down Expand Up @@ -210,7 +218,10 @@ protected function addItems(PHP_CodeCoverage_Report_HTML_Node_Directory $root, a
substr($key, 0, -2),
$value,
$this->options['yui'],
$this->options['highlight']
$this->options['highlight'],
$this->options['methodCoverageThreshold'],
$this->options['classCoverageThreshold']

);
}

Expand Down
6 changes: 4 additions & 2 deletions PHP/CodeCoverage/Report/HTML/Node/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,15 @@ public function addDirectory($name)
* @param array $lines
* @param boolean $yui
* @param boolean $highlight
* @param string $methodCoverageThreshold
* @param string $classCoverageThreshold
* @return PHP_CodeCoverage_Report_HTML_Node_File
* @throws RuntimeException
*/
public function addFile($name, array $lines, $yui, $highlight)
public function addFile($name, array $lines, $yui, $highlight, $methodCoverageThreshold, $classCoverageThreshold)
{
$file = new PHP_CodeCoverage_Report_HTML_Node_File(
$name, $this, $lines, $yui, $highlight
$name, $this, $lines, $yui, $highlight, $methodCoverageThreshold, $classCoverageThreshold
);

$this->children[] = $file;
Expand Down
31 changes: 23 additions & 8 deletions PHP/CodeCoverage/Report/HTML/Node/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ class PHP_CodeCoverage_Report_HTML_Node_File extends PHP_CodeCoverage_Report_HTM
*/
protected $endLines = array();

/**
* @var string
*/
protected $methodCoverageThreshold;

/**
* @var string
*/
protected $classCoverageThreshold;

/**
* Constructor.
*
Expand All @@ -146,9 +156,11 @@ class PHP_CodeCoverage_Report_HTML_Node_File extends PHP_CodeCoverage_Report_HTM
* @param array $executedLines
* @param boolean $yui
* @param boolean $highlight
* @param string $methodCoverageThreshold
* @param string $classCoverageThreshold
* @throws RuntimeException
*/
public function __construct($name, PHP_CodeCoverage_Report_HTML_Node $parent, array $executedLines, $yui = TRUE, $highlight = FALSE)
public function __construct($name, PHP_CodeCoverage_Report_HTML_Node $parent, array $executedLines, $yui = TRUE, $highlight = FALSE, $methodCoverageThreshold = 100, $classCoverageThreshold = 100)
{
parent::__construct($name, $parent);

Expand All @@ -167,7 +179,9 @@ public function __construct($name, PHP_CodeCoverage_Report_HTML_Node $parent, ar
$this->ignoredLines = PHP_CodeCoverage_Util::getLinesToBeIgnored(
$path
);

$this->methodCoverageThreshold = $methodCoverageThreshold;
$this->classCoverageThreshold = $classCoverageThreshold;

$this->calculateStatistics();
}

Expand Down Expand Up @@ -391,7 +405,7 @@ public function render($target, $title, $charset = 'UTF-8', $lowUpperBound = 35,
$items = '';

foreach ($this->classes as $className => $classData) {
if ($classData['executedLines'] == $classData['executableLines']) {
if ($classData['coverage'] >= $this->classCoverageThreshold) {
$numTestedClasses = 1;
$testedClassesPercent = 100;
} else {
Expand All @@ -403,7 +417,8 @@ public function render($target, $title, $charset = 'UTF-8', $lowUpperBound = 35,
$numMethods = count($classData['methods']);

foreach ($classData['methods'] as $method) {
if ($method['executedLines'] == $method['executableLines']) {

if ($method['coverage'] >= $this->methodCoverageThreshold) {
$numTestedMethods++;
}
}
Expand Down Expand Up @@ -439,8 +454,8 @@ public function render($target, $title, $charset = 'UTF-8', $lowUpperBound = 35,
);

foreach ($classData['methods'] as $methodData) {
if ($methodData['executedLines'] ==
$methodData['executableLines']) {

if ($methodData['coverage'] >= $this->methodCoverageThreshold) {
$numTestedMethods = 1;
$testedMethodsPercent = 100;
} else {
Expand Down Expand Up @@ -595,7 +610,7 @@ protected function calculateStatistics()
$method['coverage'] = 100;
}

if ($method['coverage'] == 100) {
if ($method['coverage'] >= $this->methodCoverageThreshold) {
$this->numTestedMethods++;
}

Expand All @@ -614,7 +629,7 @@ protected function calculateStatistics()
$class['coverage'] = 100;
}

if ($class['coverage'] == 100) {
if ($class['coverage'] >= $this->classCoverageThreshold) {
$this->numTestedClasses++;
}

Expand Down