mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Upgrading CodeCoverage repoting fo phpunit 3.5
This commit is contained in:
parent
45a407783e
commit
9d35ea0cbc
5 changed files with 52 additions and 158 deletions
|
@ -249,7 +249,7 @@ class TestSuiteShell extends Shell {
|
|||
$this->out("--stop-on-failure Stop execution upon first error or failure.");
|
||||
$this->out("--stop-on-skipped Stop execution upon first skipped test.");
|
||||
$this->out("--stop-on-incomplete Stop execution upon first incomplete test.");
|
||||
$this->out("--strict Mark a test as incomplete if no assertions are made.";
|
||||
$this->out("--strict Mark a test as incomplete if no assertions are made.");
|
||||
$this->out("--verbose Output more verbose information.");
|
||||
$this->out("--wait Waits for a keystroke after each test.");
|
||||
|
||||
|
|
|
@ -60,17 +60,13 @@ class HtmlCoverageReportTest extends CakeTestCase {
|
|||
*/
|
||||
function testFilterCoverageDataByPathRemovingElements() {
|
||||
$data = array(
|
||||
array(
|
||||
'files' => array(
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'dispatcher.php' => array(
|
||||
10 => -1,
|
||||
12 => 1
|
||||
),
|
||||
APP . 'app_model.php' => array(
|
||||
50 => 1,
|
||||
52 => -1
|
||||
)
|
||||
)
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'dispatcher.php' => array(
|
||||
10 => -1,
|
||||
12 => 1
|
||||
),
|
||||
APP . 'app_model.php' => array(
|
||||
50 => 1,
|
||||
52 => -1
|
||||
)
|
||||
);
|
||||
$this->Coverage->setCoverage($data);
|
||||
|
@ -79,63 +75,6 @@ class HtmlCoverageReportTest extends CakeTestCase {
|
|||
$this->assertFalse(isset($result[APP . 'app_model.php']));
|
||||
}
|
||||
|
||||
/**
|
||||
* test that filterCoverageDataByPath correctly merges data sets in each test run.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testFilterCoverageDataCorrectlyMergingValues() {
|
||||
$data = array(
|
||||
array(
|
||||
'files' => array(
|
||||
'/something/dispatcher.php' => array(
|
||||
10 => 1,
|
||||
12 => 1
|
||||
),
|
||||
),
|
||||
'executable' => array(
|
||||
'/something/dispatcher.php' => array(
|
||||
9 => -1
|
||||
)
|
||||
),
|
||||
'dead' => array(
|
||||
'/something/dispatcher.php' => array(
|
||||
22 => -2,
|
||||
23 => -2
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'files' => array(
|
||||
'/something/dispatcher.php' => array(
|
||||
10 => 1,
|
||||
50 => 1,
|
||||
),
|
||||
),
|
||||
'executable' => array(
|
||||
'/something/dispatcher.php' => array(
|
||||
12 => -1,
|
||||
51 => -1
|
||||
)
|
||||
),
|
||||
'dead' => array(
|
||||
'/something/dispatcher.php' => array(
|
||||
13 => -2,
|
||||
42 => -2
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
$this->Coverage->setCoverage($data);
|
||||
$result = $this->Coverage->filterCoverageDataByPath('/something/');
|
||||
|
||||
$path = '/something/dispatcher.php';
|
||||
$this->assertTrue(isset($result[$path]));
|
||||
$this->assertEquals(array(10, 12, 50), array_keys($result[$path]['covered']));
|
||||
$this->assertEquals(array(9, 12, 51), array_keys($result[$path]['executable']));
|
||||
$this->assertEquals(array(22, 23, 13, 42), array_keys($result[$path]['dead']));
|
||||
}
|
||||
|
||||
/**
|
||||
* test generating HTML reports from file arrays.
|
||||
*
|
||||
|
@ -155,22 +94,16 @@ class HtmlCoverageReportTest extends CakeTestCase {
|
|||
'line 10',
|
||||
);
|
||||
$coverage = array(
|
||||
'covered' => array(
|
||||
1 => 1,
|
||||
3 => 1,
|
||||
4 => 1,
|
||||
6 => 1,
|
||||
7 => 1,
|
||||
8 => 1,
|
||||
10 => 1
|
||||
),
|
||||
'executable' => array(
|
||||
5 => -1,
|
||||
9 => -1
|
||||
),
|
||||
'dead' => array(
|
||||
2 => -2
|
||||
)
|
||||
1 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
|
||||
2 => -2,
|
||||
3 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
|
||||
4 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
|
||||
5 => -1,
|
||||
6 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
|
||||
7 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
|
||||
8 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff')),
|
||||
9 => -1,
|
||||
10 => array(array('id' => 'HtmlCoverageReportTest::testGenerateDiff'))
|
||||
);
|
||||
$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
|
||||
$this->assertRegExp('/myfile\.php Code coverage\: \d+\.?\d*\%/', $result);
|
||||
|
@ -202,53 +135,28 @@ class HtmlCoverageReportTest extends CakeTestCase {
|
|||
'line 4',
|
||||
'line 5',
|
||||
);
|
||||
$mock = $this->getMock('PHPUnit_Framework_TestCase');
|
||||
$mock->expects($this->any())->method('getName')->will($this->returnValue('testAwesomeness'));
|
||||
|
||||
$rawdata = array(
|
||||
array(
|
||||
'test' => $mock,
|
||||
'files' => array(
|
||||
'myfile.php' => array(
|
||||
1 => 1,
|
||||
3 => 1,
|
||||
4 => 1,
|
||||
)
|
||||
),
|
||||
'executable' => array(
|
||||
'myfile.php' => array(
|
||||
5 => -1
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$coverage = array(
|
||||
'covered' => array(
|
||||
1 => 1,
|
||||
3 => 1,
|
||||
4 => 1,
|
||||
),
|
||||
'executable' => array(
|
||||
5 => -1,
|
||||
),
|
||||
'dead' => array(
|
||||
2 => -2
|
||||
)
|
||||
1 => array(array('id' => 'HtmlCoverageReportTest::testAwesomeness')),
|
||||
2 => -2,
|
||||
3 => array(array('id' => 'HtmlCoverageReportTest::testCakeIsSuperior')),
|
||||
4 => array(array('id' => 'HtmlCoverageReportTest::testOther')),
|
||||
5 => -1
|
||||
);
|
||||
$this->Coverage->setCoverage($rawdata);
|
||||
|
||||
|
||||
$result = $this->Coverage->generateDiff('myfile.php', $file, $coverage);
|
||||
|
||||
$this->assertTrue(
|
||||
strpos($result, "title=\"Covered by:\ntestAwesomeness\n\"><span class=\"line-num\">1") !== false,
|
||||
strpos($result, "title=\"Covered by:\nHtmlCoverageReportTest::testAwesomeness\n\"><span class=\"line-num\">1") !== false,
|
||||
'Missing method coverage for line 1'
|
||||
);
|
||||
$this->assertTrue(
|
||||
strpos($result, "title=\"Covered by:\ntestAwesomeness\n\"><span class=\"line-num\">3") !== false,
|
||||
strpos($result, "title=\"Covered by:\nHtmlCoverageReportTest::testCakeIsSuperior\n\"><span class=\"line-num\">3") !== false,
|
||||
'Missing method coverage for line 3'
|
||||
);
|
||||
$this->assertTrue(
|
||||
strpos($result, "title=\"Covered by:\ntestAwesomeness\n\"><span class=\"line-num\">4") !== false,
|
||||
strpos($result, "title=\"Covered by:\nHtmlCoverageReportTest::testOther\n\"><span class=\"line-num\">4") !== false,
|
||||
'Missing method coverage for line 4'
|
||||
);
|
||||
$this->assertTrue(
|
||||
|
|
|
@ -109,39 +109,18 @@ abstract class BaseCoverageReport {
|
|||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
$dead = isset($testRun['dead'][$filename]) ? $testRun['dead'][$filename] : array();
|
||||
$executable = isset($testRun['executable'][$filename]) ? $testRun['executable'][$filename] : array();
|
||||
|
||||
if (!isset($files[$filename])) {
|
||||
$files[$filename] = array(
|
||||
'covered' => array(),
|
||||
'dead' => array(),
|
||||
'executable' => array()
|
||||
);
|
||||
}
|
||||
$files[$filename]['covered'] += $fileCoverage;
|
||||
$files[$filename]['executable'] += $executable;
|
||||
$files[$filename]['dead'] += $dead;
|
||||
}
|
||||
if (isset($testRun['test'])) {
|
||||
$testReflection = new ReflectionClass(get_class($testRun['test']));
|
||||
list($fileBasename, $x) = explode('.', basename($testReflection->getFileName()), 2);
|
||||
$this->_testNames[] = $fileBasename;
|
||||
foreach ($this->_rawCoverage as $fileName => $fileCoverage) {
|
||||
if (strpos($fileName, $path) !== 0) {
|
||||
continue;
|
||||
}
|
||||
$files[$fileName] = $fileCoverage;
|
||||
}
|
||||
ksort($files);
|
||||
return $files;
|
||||
}
|
||||
|
||||
|
@ -155,15 +134,18 @@ abstract class BaseCoverageReport {
|
|||
protected function _calculateCoveredLines($fileLines, $coverageData) {
|
||||
$covered = $total = 0;
|
||||
|
||||
//shift line numbers forward one;
|
||||
//shift line numbers forward one
|
||||
array_unshift($fileLines, ' ');
|
||||
unset($fileLines[0]);
|
||||
|
||||
foreach ($fileLines as $lineno => $line) {
|
||||
if (isset($coverageData['covered'][$lineno])) {
|
||||
if (!isset($coverageData[$lineno])) {
|
||||
continue;
|
||||
}
|
||||
if (is_array($coverageData[$lineno])) {
|
||||
$covered++;
|
||||
$total++;
|
||||
} elseif (isset($coverageData['executable'][$lineno])) {
|
||||
} else if ($coverageData[$lineno] === -1) {
|
||||
$total++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,14 +68,18 @@ HTML;
|
|||
foreach ($fileLines as $lineno => $line) {
|
||||
$class = 'ignored';
|
||||
$coveringTests = array();
|
||||
if (isset($coverageData['covered'][$lineno])) {
|
||||
$coveringTests = PHPUnit_Util_CodeCoverage::getCoveringTests(
|
||||
$this->_rawCoverage, $filename, $lineno
|
||||
);
|
||||
if (isset($coverageData[$lineno]) && is_array($coverageData[$lineno])) {
|
||||
$coveringTests = array();
|
||||
foreach ($coverageData[$lineno] as $test) {
|
||||
$testReflection = new ReflectionClass(current(explode('::', $test['id'])));
|
||||
list($fileBasename,) = explode('.', basename($testReflection->getFileName()), 2);
|
||||
$this->_testNames[] = $fileBasename;
|
||||
$coveringTests[] = $test['id'];
|
||||
}
|
||||
$class = 'covered';
|
||||
} elseif (isset($coverageData['executable'][$lineno])) {
|
||||
} elseif (isset($coverageData[$lineno]) && $coverageData[$lineno] === -1) {
|
||||
$class = 'uncovered';
|
||||
} elseif (isset($coverageData['dead'][$lineno])) {
|
||||
} elseif (isset($coverageData[$lineno]) && $coverageData[$lineno] === -2) {
|
||||
$class .= ' dead';
|
||||
}
|
||||
$diff[] = $this->_paintLine($line, $lineno, $class, $coveringTests);
|
||||
|
@ -98,8 +102,8 @@ HTML;
|
|||
$coveredBy = '';
|
||||
if (!empty($coveringTests)) {
|
||||
$coveredBy = "Covered by:\n";
|
||||
foreach ($coveringTests as &$test) {
|
||||
$coveredBy .= $test->getName() . "\n";
|
||||
foreach ($coveringTests as $test) {
|
||||
$coveredBy .= $test . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -147,7 +147,7 @@ class CakeHtmlReporter extends CakeBaseReporter {
|
|||
echo $this->_paintLinks();
|
||||
echo '</div>';
|
||||
if (isset($this->params['codeCoverage']) && $this->params['codeCoverage']) {
|
||||
$coverage = $result->getCodeCoverageInformation();
|
||||
$coverage = $result->getCodeCoverage()->getSummary();
|
||||
echo $this->paintCoverage($coverage);
|
||||
}
|
||||
$this->paintDocumentEnd();
|
||||
|
@ -158,7 +158,7 @@ class CakeHtmlReporter extends CakeBaseReporter {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function paintCoverage($coverage) {
|
||||
public function paintCoverage(array $coverage) {
|
||||
$file = dirname(dirname(__FILE__)) . '/coverage/html_coverage_report.php';
|
||||
include_once $file;
|
||||
$reporter = new HtmlCoverageReport($coverage, $this);
|
||||
|
|
Loading…
Reference in a new issue