mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
Starting work on HtmlCoverageReport and adding a test case.
This commit is contained in:
parent
fd073809d0
commit
ac5f731940
2 changed files with 129 additions and 4 deletions
46
cake/tests/cases/libs/html_coverage_report.test.php
Normal file
46
cake/tests/cases/libs/html_coverage_report.test.php
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once CAKE . 'tests' . DS . 'lib' . DS . 'coverage' . DS . 'html_coverage_report.php';
|
||||||
|
|
||||||
|
class HtmlCoverageReportTest extends CakeTestCase {
|
||||||
|
/**
|
||||||
|
* setup
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setUp() {
|
||||||
|
$reporter = new CakeBaseReporter();
|
||||||
|
$reporter->params = array('app' => false, 'plugin' => false, 'group' => false);
|
||||||
|
$coverage = array();
|
||||||
|
$this->Coverage = new HtmlCoverageReport($coverage, $reporter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test getting the path filters.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testGetPathFilter() {
|
||||||
|
$this->Coverage->appTest = false;
|
||||||
|
$result = $this->Coverage->getPathFilter();
|
||||||
|
$this->assertEquals(TEST_CAKE_CORE_INCLUDE_PATH, $result);
|
||||||
|
|
||||||
|
$this->Coverage->appTest = true;
|
||||||
|
$result = $this->Coverage->getPathFilter();
|
||||||
|
$this->assertEquals(ROOT . DS . APP_DIR . DS, $result);
|
||||||
|
|
||||||
|
$this->Coverage->appTest = false;
|
||||||
|
$this->Coverage->pluginTest = 'test_plugin';
|
||||||
|
$result = $this->Coverage->getPathFilter();
|
||||||
|
$this->assertEquals(ROOT . DS . APP_DIR . DS . 'plugins' . DS .'test_plugin' . DS, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* teardown
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function tearDown() {
|
||||||
|
unset($this->Coverage);
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,7 +12,11 @@ class HtmlCoverageReport {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $_coverage;
|
protected $_rawCoverage;
|
||||||
|
|
||||||
|
public $appTest = false;
|
||||||
|
public $pluginTest = false;
|
||||||
|
public $groupTest = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
@ -20,8 +24,35 @@ class HtmlCoverageReport {
|
||||||
* @param array $coverage Array of coverage data from PHPUnit_Test_Result
|
* @param array $coverage Array of coverage data from PHPUnit_Test_Result
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct($coverage) {
|
public function __construct($coverage, CakeBaseReporter $reporter) {
|
||||||
$this->_coverage = $coverage;
|
$this->_rawCoverage = $coverage;
|
||||||
|
$this->setParams($reporter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pulls params out of the reporter.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function setParams(CakeBaseReporter $reporter) {
|
||||||
|
if ($reporter->params['app']) {
|
||||||
|
$this->appTest = true;
|
||||||
|
}
|
||||||
|
if ($reporter->params['group']) {
|
||||||
|
$this->groupTest = true;
|
||||||
|
}
|
||||||
|
if ($reporter->params['plugin']) {
|
||||||
|
$this->pluginTest = Inflector::underscore($reporter->params['plugin']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the coverage data array
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setCoverage($coverage) {
|
||||||
|
$this->_rawCoverage = $coverage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,6 +61,54 @@ class HtmlCoverageReport {
|
||||||
* @return string compiled html report.
|
* @return string compiled html report.
|
||||||
*/
|
*/
|
||||||
public function report() {
|
public function report() {
|
||||||
|
$pathFilter = $this->getPathFilter();
|
||||||
|
$coverageData = $this->filterCoverageDataByPath($pathFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the base path that the files we are interested in live in.
|
||||||
|
* If appTest ist
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function getPathFilter() {
|
||||||
|
$path = ROOT . DS;
|
||||||
|
if ($this->appTest) {
|
||||||
|
$path .= APP_DIR . DS;
|
||||||
|
} elseif ($this->pluginTest) {
|
||||||
|
$path = App::pluginPath($this->pluginTest);
|
||||||
|
} else {
|
||||||
|
$path = TEST_CAKE_CORE_INCLUDE_PATH;
|
||||||
|
}
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters the coverage data by path. Files not in the provided path will be removed.
|
||||||
|
* This method will merge all the various test run reports as well into a single report per file.
|
||||||
|
*
|
||||||
|
* @param string $path Path to filter files by.
|
||||||
|
* @return array Array of coverage data for files that match the given path.
|
||||||
|
*/
|
||||||
|
public function filterCoverageDataByPath($path) {
|
||||||
|
$files = array();
|
||||||
|
foreach ($this->_rawCoverage as $testRun) {
|
||||||
|
foreach ($testRun['files'] as $filename => $fileCoverage) {
|
||||||
|
if (strpos($filename, $path) !== 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!isset($files[$filename])) {
|
||||||
|
$files[$filename] = array();
|
||||||
|
}
|
||||||
|
foreach ($fileCoverage as $line => $value) {
|
||||||
|
if (!isset($files[$filename][$line])) {
|
||||||
|
$files[$filename][$line] = $value;
|
||||||
|
} elseif ($files[$filename][$line] < $value) {
|
||||||
|
$files[$filename][$line] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $files;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue