From 554c26a9f38c26cc193c354044d5417bf025f34d Mon Sep 17 00:00:00 2001 From: meus Date: Fri, 10 Aug 2007 23:18:09 +0000 Subject: [PATCH] fixing code coverage report --- tests/cc.php | 108 +++++++++++++++++++++++++++++++++++++++++++++ tests/coverage.php | 15 ++++--- tests/coverage.txt | 2 +- tests/run.php | 77 ++++++-------------------------- 4 files changed, 133 insertions(+), 69 deletions(-) create mode 100644 tests/cc.php diff --git a/tests/cc.php b/tests/cc.php new file mode 100644 index 000000000..77f5e4f73 --- /dev/null +++ b/tests/cc.php @@ -0,0 +1,108 @@ + $lines) { + $pos = strpos($file, $path); + if($pos === false && $pos !== 0){ + continue; + } + + $class = str_replace(DIRECTORY_SEPARATOR, '_', substr($file, strlen($path), -4)); + $class = str_replace($path, Doctrine::getPath(), $class); + + if (strpos($class, '_Interface')) { + continue; + } + + if(!class_exists($class)){ + continue; + } + + + + $total = count($lines) -1; //we have to remove one since it always reports the last line as a hit + $covered = 0; + $maybe = 0; + $notcovered = 0; + foreach($lines as $result){ + switch($result){ + case "1": + $covered++; + break; + case "-1": + $notcovered++; + break; + case "-2": + $maybe++; + break; + } + } + $covered--; //again we have to remove that last line. + $totallines += $total; + $totalcovered += $covered; + $totalnotcovered += $notcovered; + $totalmaybe += $maybe; + + if ($total === 0) { + $total = 1; + } + $percentage = round((($covered + $maybe) / $total) * 100, 2); + $coveredArray[$class] = array("covered" => $covered, "maybe" => $maybe, "notcovered"=>$notcovered, "total" => $total, "percentage" => $percentage); +} + + +//lets sort it +uasort($coveredArray, "sortArray"); +if(isset($_GET["desc"]) && $_GET["desc"] == "true"){ + $coveredArray = array_reverse($coveredArray, true); + } + + +?> +

Coverage report for Doctrine

+

Default mode shows results sorted by perentage. This can be changed with order = covered|total|maybe|notcovered|percentage and desc=true GET variables

+"; +echo "PercentageTotalCoveredMaybeNot Covered"; +print "" . TOTAL . "" . round((($totalcovered + $totalmaybe) / $totallines) * 100, 2) . " % $totallines$totalcovered$totalmaybe$totaldead"; +foreach($coveredArray as $class => $info){ + print "" . $class . "" . $info["percentage"] . " % " . $info["total"] . "" . $info["covered"] . "" . $info["maybe"] . "" . $info["notcovered"]. "" . printLink($class) . ""; +} +print ""; + +function sortArray($a, $b){ + global $key; + if ($a[$key] == $b[$key]) { + return 0; + } + return ($a[$key] < $b[$key]) ? -1 : 1; +} + +function printLink($className){ + global $path; + $className = str_replace("_", "/", $className) . ".php"; + return 'coverage'; + } + +function countCovered($value, $key){ + global $covered; + if($value >= 1){ + $covered++; + } +} diff --git a/tests/coverage.php b/tests/coverage.php index a0a32506d..25c6cec9e 100644 --- a/tests/coverage.php +++ b/tests/coverage.php @@ -2,7 +2,6 @@ // include doctrine, and register it's autoloader require_once dirname(__FILE__) . '/../lib/Doctrine.php'; spl_autoload_register(array('Doctrine', 'autoload')); -$path = "/home/bjartka/workspace/doctrine/lib/"; ?> @@ -10,7 +9,8 @@ $path = "/home/bjartka/workspace/doctrine/lib/";