From 627c95ed81de3eec49df90885dca6de5537801d6 Mon Sep 17 00:00:00 2001 From: tmont Date: Tue, 30 Jun 2009 07:17:35 +0000 Subject: [PATCH] cssified reports, made everything look prettyish --- build.xml | 17 ++-- properties/product.properties | 3 +- .../framework/reporting/CoverageReporter.php | 80 +++++++++++++++---- .../reporting/template/directory.html | 18 ++++- .../framework/reporting/template/file.html | 25 ++++-- .../framework/reporting/template/style.css | 54 +++++++++++-- src/TUnit/util/Util.php | 11 ++- tools/productize.php | 16 ++-- 8 files changed, 180 insertions(+), 44 deletions(-) diff --git a/build.xml b/build.xml index 74cc8c2..81f5962 100644 --- a/build.xml +++ b/build.xml @@ -39,13 +39,20 @@ - - + + + + - - - + + + + + + + + diff --git a/properties/product.properties b/properties/product.properties index b460012..71ea517 100644 --- a/properties/product.properties +++ b/properties/product.properties @@ -1,4 +1,5 @@ name=TUnit version=0.5.0 author="Tommy Montgomery" -website=http://tommymontgomery.com/ \ No newline at end of file +website=http://tommymontgomery.com/ +ezc=1.0 \ No newline at end of file diff --git a/src/TUnit/framework/reporting/CoverageReporter.php b/src/TUnit/framework/reporting/CoverageReporter.php index feb5eb1..08f7575 100644 --- a/src/TUnit/framework/reporting/CoverageReporter.php +++ b/src/TUnit/framework/reporting/CoverageReporter.php @@ -13,7 +13,6 @@ $newData = array(); foreach ($coverageData as $file => $data) { $classes = Util::getClassNamesFromFile($file); - //print_r($classes); $refClasses = array(); foreach ($classes as $class) { @@ -167,9 +166,17 @@ $tcloc += $methodData['cloc']; $methodStartLine = $refClass->getMethod($method)->getStartLine(); - $methodCoverage .= "    $method"; - $methodCoverage .= "$methodData[cloc] / " . ($methodData['loc'] - $methodData['dloc']) . ""; - $methodCoverage .= "" . round($methodData['cloc'] / ($methodData['loc'] - $methodData['dloc']) * 100, 2) . "%\n"; + $methodDeclaration = $method . '('; + + $refMethod = $refClass->getMethod($method); + $methodDeclaration .= Util::buildParameterDefinition($refMethod) . ')'; + unset($refMethod); + + $percentageData = self::getPercentage($methodData['cloc'], $methodData['loc'] - $methodData['dloc']); + + $methodCoverage .= "    $methodDeclaration"; + $methodCoverage .= "$methodData[cloc] / " . ($methodData['loc'] - $methodData['dloc']) . ""; + $methodCoverage .= "$percentageData[0]%\n"; $classLoc += $methodData['loc']; $classDloc += $methodData['dloc']; @@ -177,8 +184,10 @@ } $classStartLine = $refClass->getStartLine(); - $classCoverage .= "  $class$classCloc / " . ($classLoc - $classDloc) . ""; - $classCoverage .= "" . round($classCloc / ($classLoc - $classDloc) * 100, 2) . "%\n"; + $percentageData = self::getPercentage($classCloc, $classLoc - $classDloc); + $classCoverage .= "  $class"; + $classCoverage .= "$classCloc / " . ($classLoc - $classDloc) . ""; + $classCoverage .= "$percentageData[0]%\n"; $classCoverage .= $methodCoverage; } @@ -186,8 +195,10 @@ $tdloc += $classData['procedural']['dloc']; $tcloc += $classData['procedural']['cloc']; - $fileCoveragePercent = round($tcloc / max($tloc - $tdloc, 1) * 100, 2); - $fileCoverage = "$sourceFile$tcloc / " . ($tloc - $tdloc) . "$fileCoveragePercent%\n"; + $percentageData = self::getPercentage($tcloc, $tloc - $tdloc); + $fileCoverage = "$sourceFile"; + $fileCoverage .= "$tcloc / " . ($tloc - $tdloc) . ""; + $fileCoverage .= "$percentageData[0]%\n"; $fileCoverage .= $classCoverage; unset($classCoverage, $methodCoverage, $classData, $refClass); @@ -197,7 +208,7 @@ $lineNumbers = ''; for ($i = 1, $len = count($lines); $i <= $len; $i++) { - $lineNumbers .= '
' . $i . '
'; + $lineNumbers .= '
' . $i . '
'; $code .= '' . basename($subdir) . ''; - $info .= '' . $subdata['cloc'] . ' / ' . ($subdata['loc'] - $subdata['dloc']) . ''; - $info .= '' . round($subdata['cloc'] / ($subdata['loc'] - $subdata['dloc']) * 100, 2) . '%'; + $info .= '' . $subdata['cloc'] . ' / ' . ($subdata['loc'] - $subdata['dloc']) . ''; + $info .= "$percentageData[0]%"; $info .= "\n"; } //regular files in current directory foreach ($data['files'] as $file => $fileData) { + $percentageData = self::getPercentage($fileData['cloc'], $fileData['loc'] - $fileData['dloc']); $info .= '' . basename($file) . ''; - $info .= '' . $fileData['cloc'] . ' / ' . ($fileData['loc'] - $fileData['dloc']) . ''; - $info .= '' . round($fileData['cloc'] / ($fileData['loc'] - $fileData['dloc']) * 100, 2) . '%'; + $info .= '' . $fileData['cloc'] . ' / ' . ($fileData['loc'] - $fileData['dloc']) . ''; + $info .= "$percentageData[0]%"; $info .= "\n"; } @@ -342,7 +361,10 @@ '${product.name}', '${product.version}', '${product.website}', - '${product.author}' + '${product.author}', + '${php.version}', + '${xdebug.version}', + '${ezc.version}' ), array( Product::NAME . ' - Coverage Report', @@ -352,7 +374,10 @@ Product::NAME, Product::VERSION, Product::WEBSITE, - Product::AUTHOR + Product::AUTHOR, + phpversion(), + phpversion('xdebug'), + Product::EZC_VERSION ), $template ); @@ -368,6 +393,7 @@ } else { $link = '' . $baseDir . ''; } + $dirs = preg_split('@\\' . DIRECTORY_SEPARATOR . '@', str_replace($baseDir, '', dirname($path) . DIRECTORY_SEPARATOR), -1, PREG_SPLIT_NO_EMPTY); $path = ''; foreach ($dirs as $dir) { @@ -376,6 +402,7 @@ } else { $path = $path . '-' . $dir; } + if ($oneLink) { $link = $path; } else { @@ -394,6 +421,25 @@ return $old + (($new > 0) ? 1 : 0); } + private static function getPercentage($numerator, $denominator) { + $percentage = ($denominator != 0) ? round($numerator / $denominator * 100, 2) : 0; + $percentage = number_format($percentage, 2); + return array( + str_repeat(' ', 6 - strlen($percentage)) . $percentage, + self::getCoverageColor($percentage) + ); + } + + private static function getCoverageColor($percentage) { + $color = '#'; + + $color .= str_pad(dechex(255 - round($percentage * 2.55)), 2, '0', STR_PAD_LEFT); + $color .= str_pad(dechex(round($percentage * 2.55)), 2, '0', STR_PAD_LEFT); + $color .= '33'; + + return $color; + } + } ?> \ No newline at end of file diff --git a/src/TUnit/framework/reporting/template/directory.html b/src/TUnit/framework/reporting/template/directory.html index c7eb869..0e96584 100644 --- a/src/TUnit/framework/reporting/template/directory.html +++ b/src/TUnit/framework/reporting/template/directory.html @@ -13,18 +13,32 @@
+ +
+ + + + + + ${directory.coverage}