mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
"Fixing code CodeCoverageManager so code coverage can be tested when cake core is outside of the ROOT path or set in the php.ini
Cleaned up code structure." git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6891 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
17379fff80
commit
0cc0580fff
1 changed files with 49 additions and 70 deletions
|
@ -95,9 +95,9 @@ class CodeCoverageManager {
|
||||||
function start($testCaseFile, &$reporter) {
|
function start($testCaseFile, &$reporter) {
|
||||||
$manager =& CodeCoverageManager::getInstance();
|
$manager =& CodeCoverageManager::getInstance();
|
||||||
$manager->reporter = $reporter;
|
$manager->reporter = $reporter;
|
||||||
|
$testCaseFile = str_replace(DS . DS, DS, $testCaseFile);
|
||||||
$testCaseFile = str_replace(DS.DS, DS, $testCaseFile);
|
|
||||||
$thisFile = str_replace('.php', '.test.php', basename(__FILE__));
|
$thisFile = str_replace('.php', '.test.php', basename(__FILE__));
|
||||||
|
|
||||||
if (strpos($testCaseFile, $thisFile) !== false) {
|
if (strpos($testCaseFile, $thisFile) !== false) {
|
||||||
trigger_error('Xdebug supports no parallel coverage analysis - so this is not possible.', E_USER_ERROR);
|
trigger_error('Xdebug supports no parallel coverage analysis - so this is not possible.', E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
@ -105,13 +105,14 @@ class CodeCoverageManager {
|
||||||
if (isset($_GET['app'])) {
|
if (isset($_GET['app'])) {
|
||||||
$manager->appTest = true;
|
$manager->appTest = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_GET['group'])) {
|
if (isset($_GET['group'])) {
|
||||||
$manager->groupTest = true;
|
$manager->groupTest = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_GET['plugin'])) {
|
if (isset($_GET['plugin'])) {
|
||||||
$manager->pluginTest = Inflector::underscore($_GET['plugin']);
|
$manager->pluginTest = Inflector::underscore($_GET['plugin']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$manager->testCaseFile = $testCaseFile;
|
$manager->testCaseFile = $testCaseFile;
|
||||||
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
|
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
|
||||||
}
|
}
|
||||||
|
@ -127,13 +128,13 @@ class CodeCoverageManager {
|
||||||
$testObjectFile = $manager->__testObjectFileFromCaseFile($manager->testCaseFile, $manager->appTest);
|
$testObjectFile = $manager->__testObjectFileFromCaseFile($manager->testCaseFile, $manager->appTest);
|
||||||
|
|
||||||
if (!file_exists($testObjectFile)) {
|
if (!file_exists($testObjectFile)) {
|
||||||
trigger_error('This test object file is invalid: '.$testObjectFile);
|
trigger_error('This test object file is invalid: ' . $testObjectFile);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
$dump = xdebug_get_code_coverage();
|
$dump = xdebug_get_code_coverage();
|
||||||
xdebug_stop_code_coverage();
|
xdebug_stop_code_coverage();
|
||||||
$coverageData = array();
|
$coverageData = array();
|
||||||
|
|
||||||
foreach ($dump as $file => $data) {
|
foreach ($dump as $file => $data) {
|
||||||
if ($file == $testObjectFile) {
|
if ($file == $testObjectFile) {
|
||||||
$coverageData = $data;
|
$coverageData = $data;
|
||||||
|
@ -144,7 +145,6 @@ class CodeCoverageManager {
|
||||||
if (empty($coverageData) && $output) {
|
if (empty($coverageData) && $output) {
|
||||||
echo 'The test object file is never loaded.';
|
echo 'The test object file is never loaded.';
|
||||||
}
|
}
|
||||||
|
|
||||||
$execCodeLines = $manager->__getExecutableLines(file_get_contents($testObjectFile));
|
$execCodeLines = $manager->__getExecutableLines(file_get_contents($testObjectFile));
|
||||||
$result = '';
|
$result = '';
|
||||||
|
|
||||||
|
@ -164,11 +164,10 @@ class CodeCoverageManager {
|
||||||
|
|
||||||
foreach ($testObjectFiles as $file) {
|
foreach ($testObjectFiles as $file) {
|
||||||
if (!file_exists($file)) {
|
if (!file_exists($file)) {
|
||||||
trigger_error('This test object file is invalid: '.$file);
|
trigger_error('This test object file is invalid: ' . $file);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$dump = xdebug_get_code_coverage();
|
$dump = xdebug_get_code_coverage();
|
||||||
xdebug_stop_code_coverage();
|
xdebug_stop_code_coverage();
|
||||||
$coverageData = array();
|
$coverageData = array();
|
||||||
|
@ -181,7 +180,6 @@ class CodeCoverageManager {
|
||||||
if (empty($coverageData) && $output) {
|
if (empty($coverageData) && $output) {
|
||||||
echo 'The test object files are never loaded.';
|
echo 'The test object files are never loaded.';
|
||||||
}
|
}
|
||||||
|
|
||||||
$execCodeLines = $manager->__getExecutableLines($testObjectFiles);
|
$execCodeLines = $manager->__getExecutableLines($testObjectFiles);
|
||||||
$result = '';
|
$result = '';
|
||||||
|
|
||||||
|
@ -218,7 +216,6 @@ class CodeCoverageManager {
|
||||||
|
|
||||||
foreach ($testObjectFile as $num => $line) {
|
foreach ($testObjectFile as $num => $line) {
|
||||||
$num++;
|
$num++;
|
||||||
|
|
||||||
$foundByManualFinder = array_key_exists($num, $execCodeLines) && trim($execCodeLines[$num]) != '';
|
$foundByManualFinder = array_key_exists($num, $execCodeLines) && trim($execCodeLines[$num]) != '';
|
||||||
$foundByXdebug = array_key_exists($num, $coverageData) && $coverageData[$num] !== -2;
|
$foundByXdebug = array_key_exists($num, $coverageData) && $coverageData[$num] !== -2;
|
||||||
|
|
||||||
|
@ -236,7 +233,6 @@ class CodeCoverageManager {
|
||||||
}
|
}
|
||||||
$report .= $manager->__paintCodeline($class, $num, $line);;
|
$report .= $manager->__paintCodeline($class, $num, $line);;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $manager->__paintHeader($lineCount, $coveredCount, $report);
|
return $manager->__paintHeader($lineCount, $coveredCount, $report);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -259,7 +255,7 @@ class CodeCoverageManager {
|
||||||
|
|
||||||
if (!$foundByManualFinder || !$foundByXdebug || $coverageData[$i] === -2) {
|
if (!$foundByManualFinder || !$foundByXdebug || $coverageData[$i] === -2) {
|
||||||
if (array_key_exists($i, $lines)) {
|
if (array_key_exists($i, $lines)) {
|
||||||
$lines[$i] = 'ignored '.$lines[$i];
|
$lines[$i] = 'ignored ' . $lines[$i];
|
||||||
} else {
|
} else {
|
||||||
$lines[$i] = 'ignored';
|
$lines[$i] = 'ignored';
|
||||||
}
|
}
|
||||||
|
@ -268,15 +264,15 @@ class CodeCoverageManager {
|
||||||
|
|
||||||
if ($coverageData[$i] !== -1) {
|
if ($coverageData[$i] !== -1) {
|
||||||
if (array_key_exists($i, $lines)) {
|
if (array_key_exists($i, $lines)) {
|
||||||
$lines[$i] = 'covered '.$lines[$i];
|
$lines[$i] = 'covered ' . $lines[$i];
|
||||||
} else {
|
} else {
|
||||||
$lines[$i] = 'covered';
|
$lines[$i] = 'covered';
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$lines[$i] = 'uncovered show';
|
$lines[$i] = 'uncovered show';
|
||||||
|
|
||||||
$foundEndBlockInContextSearch = false;
|
$foundEndBlockInContextSearch = false;
|
||||||
|
|
||||||
for ($j = 1; $j <= $numContextLines; $j++) {
|
for ($j = 1; $j <= $numContextLines; $j++) {
|
||||||
$key = $i - $j;
|
$key = $i - $j;
|
||||||
|
|
||||||
|
@ -310,8 +306,8 @@ class CodeCoverageManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$key = $i + $j;
|
$key = $i + $j;
|
||||||
|
|
||||||
if ($key < $total) {
|
if ($key < $total) {
|
||||||
$lines[$key] = 'show';
|
$lines[$key] = 'show';
|
||||||
|
|
||||||
|
@ -321,19 +317,17 @@ class CodeCoverageManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// find the last "uncovered" or "show"n line and "end" its block
|
// find the last "uncovered" or "show"n line and "end" its block
|
||||||
$lastShownLine = $manager->__array_strpos($lines, 'show', true);
|
$lastShownLine = $manager->__array_strpos($lines, 'show', true);
|
||||||
|
|
||||||
if (isset($lines[$lastShownLine])) {
|
if (isset($lines[$lastShownLine])) {
|
||||||
$lines[$lastShownLine] .= ' end';
|
$lines[$lastShownLine] .= ' end';
|
||||||
}
|
}
|
||||||
|
|
||||||
// give the first start line another class so we can control the top padding of the entire results
|
// give the first start line another class so we can control the top padding of the entire results
|
||||||
$firstShownLine = $manager->__array_strpos($lines, 'show');
|
$firstShownLine = $manager->__array_strpos($lines, 'show');
|
||||||
if (isset($lines[$firstShownLine])) {
|
if (isset($lines[$firstShownLine])) {
|
||||||
$lines[$firstShownLine] .= ' realstart';
|
$lines[$firstShownLine] .= ' realstart';
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the output
|
// get the output
|
||||||
$lineCount = $coveredCount = 0;
|
$lineCount = $coveredCount = 0;
|
||||||
$report = '';
|
$report = '';
|
||||||
|
@ -354,7 +348,6 @@ class CodeCoverageManager {
|
||||||
$report .= $manager->__paintCodeline($class, $num, $line);
|
$report .= $manager->__paintCodeline($class, $num, $line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $manager->__paintHeader($lineCount, $coveredCount, $report);
|
return $manager->__paintHeader($lineCount, $coveredCount, $report);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -373,7 +366,6 @@ class CodeCoverageManager {
|
||||||
|
|
||||||
foreach ($testObjectFile as $num => $line) {
|
foreach ($testObjectFile as $num => $line) {
|
||||||
$num++;
|
$num++;
|
||||||
|
|
||||||
$foundByManualFinder = array_key_exists($num, $execCodeLines) && trim($execCodeLines[$num]) != '';
|
$foundByManualFinder = array_key_exists($num, $execCodeLines) && trim($execCodeLines[$num]) != '';
|
||||||
$foundByXdebug = array_key_exists($num, $coverageData) && $coverageData[$num] !== -2;
|
$foundByXdebug = array_key_exists($num, $coverageData) && $coverageData[$num] !== -2;
|
||||||
|
|
||||||
|
@ -385,7 +377,6 @@ class CodeCoverageManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $manager->__paintHeaderCli($lineCount, $coveredCount, $report);
|
return $manager->__paintHeaderCli($lineCount, $coveredCount, $report);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -408,7 +399,6 @@ class CodeCoverageManager {
|
||||||
|
|
||||||
foreach ($testObjectFile as $num => $line) {
|
foreach ($testObjectFile as $num => $line) {
|
||||||
$num++;
|
$num++;
|
||||||
|
|
||||||
$foundByManualFinder = array_key_exists($num, $execCodeLines[$objFilename]) && trim($execCodeLines[$objFilename][$num]) != '';
|
$foundByManualFinder = array_key_exists($num, $execCodeLines[$objFilename]) && trim($execCodeLines[$objFilename][$num]) != '';
|
||||||
$foundByXdebug = array_key_exists($num, $coverageData[$objFilename]) && $coverageData[$objFilename][$num] !== -2;
|
$foundByXdebug = array_key_exists($num, $coverageData[$objFilename]) && $coverageData[$objFilename][$num] !== -2;
|
||||||
|
|
||||||
|
@ -424,7 +414,6 @@ class CodeCoverageManager {
|
||||||
$class = 'ignored';
|
$class = 'ignored';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$report .= $manager->__paintGroupResultLine($objFilename, $lineCount, $coveredCount);
|
$report .= $manager->__paintGroupResultLine($objFilename, $lineCount, $coveredCount);
|
||||||
}
|
}
|
||||||
return $manager->__paintGroupResultHeader($report);
|
return $manager->__paintGroupResultHeader($report);
|
||||||
|
@ -449,7 +438,6 @@ class CodeCoverageManager {
|
||||||
|
|
||||||
foreach ($testObjectFile as $num => $line) {
|
foreach ($testObjectFile as $num => $line) {
|
||||||
$num++;
|
$num++;
|
||||||
|
|
||||||
$foundByManualFinder = array_key_exists($num, $execCodeLines[$objFilename]) && trim($execCodeLines[$objFilename][$num]) != '';
|
$foundByManualFinder = array_key_exists($num, $execCodeLines[$objFilename]) && trim($execCodeLines[$objFilename][$num]) != '';
|
||||||
$foundByXdebug = array_key_exists($num, $coverageData[$objFilename]) && $coverageData[$objFilename][$num] !== -2;
|
$foundByXdebug = array_key_exists($num, $coverageData[$objFilename]) && $coverageData[$objFilename][$num] !== -2;
|
||||||
|
|
||||||
|
@ -461,10 +449,8 @@ class CodeCoverageManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$report .= $manager->__paintGroupResultLineCli($objFilename, $lineCount, $coveredCount);
|
$report .= $manager->__paintGroupResultLineCli($objFilename, $lineCount, $coveredCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $report;
|
return $report;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -478,32 +464,32 @@ class CodeCoverageManager {
|
||||||
function __testObjectFileFromCaseFile($file, $isApp = true) {
|
function __testObjectFileFromCaseFile($file, $isApp = true) {
|
||||||
$manager = CodeCoverageManager::getInstance();
|
$manager = CodeCoverageManager::getInstance();
|
||||||
$path = $manager->__getTestFilesPath($isApp);
|
$path = $manager->__getTestFilesPath($isApp);
|
||||||
|
|
||||||
$folderPrefixMap = array(
|
$folderPrefixMap = array(
|
||||||
'behaviors' => 'models',
|
'behaviors' => 'models',
|
||||||
'components' => 'controllers',
|
'components' => 'controllers',
|
||||||
'helpers' => 'views'
|
'helpers' => 'views'
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($folderPrefixMap as $dir => $prefix) {
|
foreach ($folderPrefixMap as $dir => $prefix) {
|
||||||
if (strpos($file, $dir) === 0) {
|
if (strpos($file, $dir) === 0) {
|
||||||
$path .= $prefix.DS;
|
$path .= $prefix . DS;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$testManager =& new TestManager();
|
$testManager =& new TestManager();
|
||||||
$testFile = str_replace(array('/', $testManager->_testExtension), array(DS, '.php'), $file);
|
$testFile = str_replace(array('/', $testManager->_testExtension), array(DS, '.php'), $file);
|
||||||
|
|
||||||
$folder =& new Folder();
|
$folder =& new Folder();
|
||||||
$folder->cd(ROOT.DS.CAKE_TESTS_LIB);
|
$folder->cd(ROOT . DS . CAKE_TESTS_LIB);
|
||||||
$contents = $folder->ls();
|
$contents = $folder->ls();
|
||||||
|
|
||||||
if (in_array(basename($testFile), $contents[1])) {
|
if (in_array(basename($testFile), $contents[1])) {
|
||||||
$testFile = basename($testFile);
|
$testFile = basename($testFile);
|
||||||
$path = ROOT.DS.CAKE_TESTS_LIB;
|
$path = ROOT . DS . CAKE_TESTS_LIB;
|
||||||
}
|
}
|
||||||
$path .= $testFile;
|
$path .= $testFile;
|
||||||
$realpath = realpath($path);
|
$realpath = realpath($path);
|
||||||
|
|
||||||
if ($realpath) {
|
if ($realpath) {
|
||||||
return $realpath;
|
return $realpath;
|
||||||
}
|
}
|
||||||
|
@ -521,27 +507,28 @@ class CodeCoverageManager {
|
||||||
$manager = CodeCoverageManager::getInstance();
|
$manager = CodeCoverageManager::getInstance();
|
||||||
$testManager =& new TestManager();
|
$testManager =& new TestManager();
|
||||||
|
|
||||||
$path = TESTS.'groups';
|
$path = TESTS . 'groups';
|
||||||
|
|
||||||
if (!$isApp) {
|
if (!$isApp) {
|
||||||
$path = ROOT.DS.'cake'.DS.'tests'.DS.'groups';
|
$path = ROOT . DS . 'cake' . DS . 'tests' . DS . 'groups';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!!$manager->pluginTest) {
|
if (!!$manager->pluginTest) {
|
||||||
$path = APP.'plugins'.DS.$manager->pluginTest.DS.'tests'.DS.'groups';
|
$path = APP . 'plugins' . DS . $manager->pluginTest . DS . 'tests' . DS . 'groups';
|
||||||
}
|
}
|
||||||
$path .= DS.$groupFile.$testManager->_groupExtension;
|
$path .= DS . $groupFile . $testManager->_groupExtension;
|
||||||
|
|
||||||
if (!file_exists($path)) {
|
if (!file_exists($path)) {
|
||||||
trigger_error('This group file does not exist!');
|
trigger_error('This group file does not exist!');
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
$result = array();
|
||||||
$groupContent = file_get_contents($path);
|
$groupContent = file_get_contents($path);
|
||||||
$ds = '\s*\.\s*DS\s*\.\s*';
|
$ds = '\s*\.\s*DS\s*\.\s*';
|
||||||
$pluginTest = 'APP\.\'plugins\''.$ds.'\''.$manager->pluginTest.'\''.$ds.'\'tests\''.$ds.'\'cases\'';
|
$pluginTest = 'APP\.\'plugins\'' . $ds . '\'' . $manager->pluginTest . '\'' . $ds . '\'tests\'' . $ds . '\'cases\'';
|
||||||
$pattern = '/\s*TestManager::addTestFile\(\s*\$this,\s*('.$pluginTest.'|APP_TEST_CASES|CORE_TEST_CASES)'.$ds.'(.*?)\)/i';
|
$pattern = '/\s*TestManager::addTestFile\(\s*\$this,\s*(' . $pluginTest . '|APP_TEST_CASES|CORE_TEST_CASES)' . $ds . '(.*?)\)/i';
|
||||||
preg_match_all($pattern, $groupContent, $matches);
|
preg_match_all($pattern, $groupContent, $matches);
|
||||||
|
|
||||||
$result = array();
|
|
||||||
foreach ($matches[2] as $file) {
|
foreach ($matches[2] as $file) {
|
||||||
$patterns = array(
|
$patterns = array(
|
||||||
'/\s*\.\s*DS\s*\.\s*/',
|
'/\s*\.\s*DS\s*\.\s*/',
|
||||||
|
@ -551,9 +538,8 @@ class CodeCoverageManager {
|
||||||
$replacements = array(DS, '', '');
|
$replacements = array(DS, '', '');
|
||||||
$file = preg_replace($patterns, $replacements, $file);
|
$file = preg_replace($patterns, $replacements, $file);
|
||||||
$file = str_replace("'", '', $file);
|
$file = str_replace("'", '', $file);
|
||||||
$result[] = $manager->__testObjectFileFromCaseFile($file, $isApp).'.php';
|
$result[] = $manager->__testObjectFileFromCaseFile($file, $isApp) . '.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -573,26 +559,19 @@ class CodeCoverageManager {
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = h($content);
|
$content = h($content);
|
||||||
|
|
||||||
// arrays are 0-indexed, but we want 1-indexed stuff now as we are talking code lines mind you (**)
|
// arrays are 0-indexed, but we want 1-indexed stuff now as we are talking code lines mind you (**)
|
||||||
$content = "\n".$content;
|
$content = "\n" . $content;
|
||||||
|
|
||||||
// // strip unwanted lines
|
// // strip unwanted lines
|
||||||
$content = preg_replace_callback("/(@codeCoverageIgnoreStart.*?@codeCoverageIgnoreEnd)/is", array('CodeCoverageManager', '__replaceWithNewlines'), $content);
|
$content = preg_replace_callback("/(@codeCoverageIgnoreStart.*?@codeCoverageIgnoreEnd)/is", array('CodeCoverageManager', '__replaceWithNewlines'), $content);
|
||||||
|
|
||||||
// strip php | ?\> tag only lines
|
// strip php | ?\> tag only lines
|
||||||
$content = preg_replace('/[ |\t]*[<\?php|\?>]+[ |\t]*/', '', $content);
|
$content = preg_replace('/[ |\t]*[<\?php|\?>]+[ |\t]*/', '', $content);
|
||||||
|
|
||||||
// strip lines that contain only braces and parenthesis
|
// strip lines that contain only braces and parenthesis
|
||||||
$content = preg_replace('/[ |\t]*[{|}|\(|\)]+[ |\t]*/', '', $content);
|
$content = preg_replace('/[ |\t]*[{|}|\(|\)]+[ |\t]*/', '', $content);
|
||||||
|
|
||||||
$result = explode("\n", $content);
|
$result = explode("\n", $content);
|
||||||
|
|
||||||
// unset the zero line again to get the original line numbers, but starting at 1, see (**)
|
// unset the zero line again to get the original line numbers, but starting at 1, see (**)
|
||||||
unset($result[0]);
|
unset($result[0]);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -604,7 +583,7 @@ class CodeCoverageManager {
|
||||||
function __replaceWithNewlines() {
|
function __replaceWithNewlines() {
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
$numLineBreaks = count(explode("\n", $args[0][0]));
|
$numLineBreaks = count(explode("\n", $args[0][0]));
|
||||||
return str_pad('', $numLineBreaks-1, "\n");
|
return str_pad('', $numLineBreaks - 1, "\n");
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Paints the headline for code coverage analysis
|
* Paints the headline for code coverage analysis
|
||||||
|
@ -617,9 +596,8 @@ class CodeCoverageManager {
|
||||||
function __paintHeader($lineCount, $coveredCount, $report) {
|
function __paintHeader($lineCount, $coveredCount, $report) {
|
||||||
$manager =& CodeCoverageManager::getInstance();
|
$manager =& CodeCoverageManager::getInstance();
|
||||||
$codeCoverage = $manager->__calcCoverage($lineCount, $coveredCount);
|
$codeCoverage = $manager->__calcCoverage($lineCount, $coveredCount);
|
||||||
|
return $report = '<h2>Code Coverage: ' . $codeCoverage . '%</h2>
|
||||||
return $report = '<h2>Code Coverage: '.$codeCoverage.'%</h2>
|
<div class="code-coverage-results"><pre>' . $report . '</pre></div>';
|
||||||
<div class="code-coverage-results"><pre>'.$report.'</pre></div>';
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Displays a notification concerning group test results
|
* Displays a notification concerning group test results
|
||||||
|
@ -628,7 +606,7 @@ class CodeCoverageManager {
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function __paintGroupResultHeader($report) {
|
function __paintGroupResultHeader($report) {
|
||||||
return '<div class="code-coverage-results"><p class="note">Please keep in mind that the coverage can vary a little bit depending on how much the different tests in the group interfere. If for example, TEST A calls a line from TEST OBJECT B, the coverage for TEST OBJECT B will be a little greater than if you were running the corresponding test case for TEST OBJECT B alone.</p><pre>'.$report.'</pre></div>';
|
return '<div class="code-coverage-results"><p class="note">Please keep in mind that the coverage can vary a little bit depending on how much the different tests in the group interfere. If for example, TEST A calls a line from TEST OBJECT B, the coverage for TEST OBJECT B will be a little greater than if you were running the corresponding test case for TEST OBJECT B alone.</p><pre>' . $report . '</pre></div>';
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Paints the headline for code coverage analysis
|
* Paints the headline for code coverage analysis
|
||||||
|
@ -641,15 +619,15 @@ class CodeCoverageManager {
|
||||||
function __paintGroupResultLine($file, $lineCount, $coveredCount) {
|
function __paintGroupResultLine($file, $lineCount, $coveredCount) {
|
||||||
$manager =& CodeCoverageManager::getInstance();
|
$manager =& CodeCoverageManager::getInstance();
|
||||||
$codeCoverage = $manager->__calcCoverage($lineCount, $coveredCount);
|
$codeCoverage = $manager->__calcCoverage($lineCount, $coveredCount);
|
||||||
|
|
||||||
$class = 'result-bad';
|
$class = 'result-bad';
|
||||||
|
|
||||||
if ($codeCoverage > 50) {
|
if ($codeCoverage > 50) {
|
||||||
$class = 'result-ok';
|
$class = 'result-ok';
|
||||||
}
|
}
|
||||||
if ($codeCoverage > 80) {
|
if ($codeCoverage > 80) {
|
||||||
$class = 'result-good';
|
$class = 'result-good';
|
||||||
}
|
}
|
||||||
return '<p>Code Coverage for '.$file.': <span class="'.$class.'">'.$codeCoverage.'%</span></p>';
|
return '<p>Code Coverage for ' . $file . ': <span class="' . $class . '">' . $codeCoverage . '%</span></p>';
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Paints the headline for code coverage analysis
|
* Paints the headline for code coverage analysis
|
||||||
|
@ -662,15 +640,15 @@ class CodeCoverageManager {
|
||||||
function __paintGroupResultLineCli($file, $lineCount, $coveredCount) {
|
function __paintGroupResultLineCli($file, $lineCount, $coveredCount) {
|
||||||
$manager =& CodeCoverageManager::getInstance();
|
$manager =& CodeCoverageManager::getInstance();
|
||||||
$codeCoverage = $manager->__calcCoverage($lineCount, $coveredCount);
|
$codeCoverage = $manager->__calcCoverage($lineCount, $coveredCount);
|
||||||
|
|
||||||
$class = 'bad';
|
$class = 'bad';
|
||||||
|
|
||||||
if ($codeCoverage > 50) {
|
if ($codeCoverage > 50) {
|
||||||
$class = 'ok';
|
$class = 'ok';
|
||||||
}
|
}
|
||||||
if ($codeCoverage > 80) {
|
if ($codeCoverage > 80) {
|
||||||
$class = 'good';
|
$class = 'good';
|
||||||
}
|
}
|
||||||
return "\n".'Code Coverage for '.$file.': '.$codeCoverage.'% ('.$class.')'."\n";
|
return "\n" . 'Code Coverage for ' . $file . ': ' . $codeCoverage . '% (' . $class . ')' . "\n";
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Paints the headline for code coverage analysis in the CLI
|
* Paints the headline for code coverage analysis in the CLI
|
||||||
|
@ -683,8 +661,7 @@ class CodeCoverageManager {
|
||||||
function __paintHeaderCli($lineCount, $coveredCount, $report) {
|
function __paintHeaderCli($lineCount, $coveredCount, $report) {
|
||||||
$manager =& CodeCoverageManager::getInstance();
|
$manager =& CodeCoverageManager::getInstance();
|
||||||
$codeCoverage = $manager->__calcCoverage($lineCount, $coveredCount);
|
$codeCoverage = $manager->__calcCoverage($lineCount, $coveredCount);
|
||||||
|
return $report = 'Code Coverage: ' . $codeCoverage . '%';
|
||||||
return $report = 'Code Coverage: '.$codeCoverage.'%';
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Paints a code line for html output
|
* Paints a code line for html output
|
||||||
|
@ -694,10 +671,11 @@ class CodeCoverageManager {
|
||||||
*/
|
*/
|
||||||
function __paintCodeline($class, $num, $line) {
|
function __paintCodeline($class, $num, $line) {
|
||||||
$line = h($line);
|
$line = h($line);
|
||||||
|
|
||||||
if (trim($line) == '') {
|
if (trim($line) == '') {
|
||||||
$line = ' '; // Win IE fix
|
$line = ' '; // Win IE fix
|
||||||
}
|
}
|
||||||
return '<div class="code-line '.trim($class).'"><span class="line-num">'.$num.'</span><span class="content">'.$line.'</span></div>';
|
return '<div class="code-line ' . trim($class) . '"><span class="line-num">' . $num . '</span><span class="content">' . $line . '</span></div>';
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Calculates the coverage percentage based on a line count and a covered line count
|
* Calculates the coverage percentage based on a line count and a covered line count
|
||||||
|
@ -712,7 +690,7 @@ class CodeCoverageManager {
|
||||||
trigger_error('Sorry, you cannot have more covered lines than total lines!');
|
trigger_error('Sorry, you cannot have more covered lines than total lines!');
|
||||||
}
|
}
|
||||||
return ($lineCount != 0)
|
return ($lineCount != 0)
|
||||||
? round(100*$coveredCount/$lineCount, 2)
|
? round(100 * $coveredCount / $lineCount, 2)
|
||||||
: '0.00';
|
: '0.00';
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -724,15 +702,15 @@ class CodeCoverageManager {
|
||||||
*/
|
*/
|
||||||
function __getTestFilesPath($isApp = true) {
|
function __getTestFilesPath($isApp = true) {
|
||||||
$manager = CodeCoverageManager::getInstance();
|
$manager = CodeCoverageManager::getInstance();
|
||||||
$path = ROOT.DS;
|
$path = ROOT . DS;
|
||||||
if ($isApp) {
|
|
||||||
$path .= APP_DIR.DS;
|
|
||||||
} elseif (!!$manager->pluginTest) {
|
|
||||||
$path .= APP_DIR.DS.'plugins'.DS.$manager->pluginTest.DS;
|
|
||||||
} else {
|
|
||||||
$path = ROOT.DS.'cake'.DS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if ($isApp) {
|
||||||
|
$path .= APP_DIR . DS;
|
||||||
|
} elseif (!!$manager->pluginTest) {
|
||||||
|
$path .= APP_DIR . DS . 'plugins' . DS . $manager->pluginTest . DS;
|
||||||
|
} else {
|
||||||
|
$path = TEST_CAKE_CORE_INCLUDE_PATH;
|
||||||
|
}
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -751,6 +729,7 @@ class CodeCoverageManager {
|
||||||
if ($reverse) {
|
if ($reverse) {
|
||||||
$arr = array_reverse($arr, true);
|
$arr = array_reverse($arr, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($arr as $key => $val) {
|
foreach ($arr as $key => $val) {
|
||||||
if (strpos($val, $needle) !== false) {
|
if (strpos($val, $needle) !== false) {
|
||||||
return $key;
|
return $key;
|
||||||
|
|
Loading…
Reference in a new issue