Coverage for ' . $_GET["file"] . ''; echo 'Back to coverage report'; $reporter->showFile($_GET["file"]); }else{ ?>

Coverage report for Doctrine

Default mode shows results sorted by percentage. This can be changed with GET variables:

showSummary(); echo "
PercentageTotalCoveredMaybeNot Covered
"; } ?> path = $result["path"]; $this->coverage = $result["coverage"]; $this->sortBy ="percentage"; // default sort } public function showFile($fileName) { $key = $this->path . $fileName; $html = '
'; if( !isset( $this->coverage[$key])) { echo '

This file has not been tested!

'; } $coveredLines = $this->coverage[$key]; $fileArray = file(Doctrine::getPath() . "/".$fileName); $html .= '
' . "\n"; foreach( $fileArray as $num => $line){ $linenum = $num+1; $html .= '
' . $linenum . '
' . "\n"; $class ="normal"; if( isset($coveredLines[$linenum]) && $coveredLines[$linenum] == 1){ $class = "covered"; }else if( isset($coveredLines[$linenum]) && $coveredLines[$linenum] == -1){ $class ="red"; }else if( isset($coveredLines[$linenum]) && $coveredLines[$linenum] == -2){ $class ="orange"; } $html .= '
' . htmlspecialchars($line) . '
' . "\n"; } $html .='
'; echo $html; } public function generateNotCoveredFiles() { $it = new RecursiveDirectoryIterator(Doctrine::getPath()); $notCoveredArray = array(); foreach( new RecursiveIteratorIterator($it) as $file){ if( strpos($file->getPathname(), ".svn")){ continue; } $path = Doctrine::getPath() . DIRECTORY_SEPARATOR; $coveredPath = str_replace($path, $this->path, $file->getPathname()); if( isset($this->coverage[$coveredPath])){ continue; } $class = str_replace($path, "", $file->getPathname()); $class = str_replace(DIRECTORY_SEPARATOR, "_", $class); $class = substr($class, 0,-4); if (strpos($class, '_Interface')) { continue; } if(!class_exists($class)){ continue; } try{ $refClass = new ReflectionClass($class); }catch(Exception $e){ echo $e->getMessage(); continue; } $lines = 0; $methodLines = 0; foreach($refClass->getMethods() as $refMethod){ if($refMethod->getDeclaringClass() != $refClass){ continue; } $methodLines = $refMethod->getEndLine() - $refMethod->getStartLine(); $lines += $methodLines; } if($methodLines == 0){ $notCoveredArray[$class] = array("covered" => 0, "maybe" => 0, "notcovered"=>$lines, "total" => $lines, "percentage" => 100); }else{ $notCoveredArray[$class] = array("covered" => 0, "maybe" => 0, "notcovered"=>$lines, "total" => $lines, "percentage" => 0); } $this->totallines += $lines; $this->totalnotcovered += $lines; } return $notCoveredArray; } public function showSummary() { if(isset($_GET["order"])){ $this->sortBy = $_GET["order"]; } $coveredArray = $this->generateCoverage(); $notcoveredArray = $this->generateNotCoveredFiles(); $coveredArray = array_merge($coveredArray, $notcoveredArray); //lets sort it. uasort($coveredArray, array($this,"sortArray")); //and flip if it perhaps? if(isset($_GET["desc"]) && $_GET["desc"] == "true"){ $coveredArray = array_reverse($coveredArray, true); } //ugly code to print out the result: echo "" . TOTAL . "" . round((($this->totalcovered + $this->totalmaybe) / $this->totallines) * 100, 2) . " % $this->totallines$this->totalcovered$this->totalmaybe$this->totalnotcovered"; foreach($coveredArray as $class => $info){ $fileName = str_replace("_", "/", $class) . ".php"; echo "" . $class . "" . $info["percentage"] . " % " . $info["total"] . "" . $info["covered"] . "" . $info["maybe"] . "" . $info["notcovered"]. "coverage"; } } public function generateCoverage() { $coveredArray = array(); foreach ($this->coverage as $file => $lines) { $pos = strpos($file, $this->path); if($pos === false && $pos !== 0){ continue; } $class = str_replace(DIRECTORY_SEPARATOR, '_', substr($file, strlen($this->path), -4)); $class = str_replace($this->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 self::COVERED: $covered++; break; case self::NOTCOVERED: $notcovered++; break; case self::MAYBE: $maybe++; break; } } $covered--; //again we have to remove that last line. $this->totallines += $total; $this->totalcovered += $covered; $this->totalnotcovered += $notcovered; $this->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); } return $coveredArray; } public function sortArray($a, $b) { if ($a[$this->sortBy] == $b[$this->sortBy]) { return 0; } return ($a[$this->sortBy] < $b[$this->sortBy]) ? -1 : 1; } }