cssified reports, made everything look prettyish

This commit is contained in:
tmont 2009-06-30 07:17:35 +00:00
parent dafa6ebffa
commit 627c95ed81
8 changed files with 180 additions and 44 deletions

View File

@ -39,13 +39,20 @@
<target name="product" depends="init, set-revision-number" description="Generates Product.php (product meta information)"> <target name="product" depends="init, set-revision-number" description="Generates Product.php (product meta information)">
<exec executable="php"> <exec executable="php">
<arg line="${dir.tools}/productize.php"/> <arg line="${dir.tools}/productize.php"/>
<arg line="-n ${product.name}"/> <arg line="-n"/>
<arg line="-v ${product.version}.${product.revision}"/> <arg line="${product.name}"/>
<arg line="-v"/>
<arg line="${product.version}.${product.revision}"/>
<arg line="-a"/> <arg line="-a"/>
<arg line="${product.author}"/> <arg line="${product.author}"/>
<arg line="-w ${product.website}"/> <arg line="-e"/>
<arg line="-p ${ant.project.name}"/> <arg line="${product.ezc}"/>
<arg line="-o ${dir.src}/${ant.project.name}/util/Product.php"/> <arg line="-w"/>
<arg line="${product.website}"/>
<arg line="-p"/>
<arg line="${ant.project.name}"/>
<arg line="-o"/>
<arg line="${dir.src}/${ant.project.name}/util/Product.php"/>
</exec> </exec>
</target> </target>

View File

@ -1,4 +1,5 @@
name=TUnit name=TUnit
version=0.5.0 version=0.5.0
author="Tommy Montgomery" author="Tommy Montgomery"
website=http://tommymontgomery.com/ website=http://tommymontgomery.com/
ezc=1.0

View File

@ -13,7 +13,6 @@
$newData = array(); $newData = array();
foreach ($coverageData as $file => $data) { foreach ($coverageData as $file => $data) {
$classes = Util::getClassNamesFromFile($file); $classes = Util::getClassNamesFromFile($file);
//print_r($classes);
$refClasses = array(); $refClasses = array();
foreach ($classes as $class) { foreach ($classes as $class) {
@ -167,9 +166,17 @@
$tcloc += $methodData['cloc']; $tcloc += $methodData['cloc'];
$methodStartLine = $refClass->getMethod($method)->getStartLine(); $methodStartLine = $refClass->getMethod($method)->getStartLine();
$methodCoverage .= "<tr class=\"method-coverage\"><th>&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"#line-$methodStartLine\">$method</a></th>"; $methodDeclaration = $method . '(';
$methodCoverage .= "<td>$methodData[cloc] / " . ($methodData['loc'] - $methodData['dloc']) . "</td>";
$methodCoverage .= "<td>" . round($methodData['cloc'] / ($methodData['loc'] - $methodData['dloc']) * 100, 2) . "%</td></tr>\n"; $refMethod = $refClass->getMethod($method);
$methodDeclaration .= Util::buildParameterDefinition($refMethod) . ')';
unset($refMethod);
$percentageData = self::getPercentage($methodData['cloc'], $methodData['loc'] - $methodData['dloc']);
$methodCoverage .= "<tr class=\"method-coverage\"><th>&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"#line-$methodStartLine\">$methodDeclaration</a></th>";
$methodCoverage .= "<td class=\"coverage-ratio\" style=\"background-color: $percentageData[1]\">$methodData[cloc] / " . ($methodData['loc'] - $methodData['dloc']) . "</td>";
$methodCoverage .= "<td class=\"coverage-percentage\" style=\"background-color: $percentageData[1]\">$percentageData[0]%</td></tr>\n";
$classLoc += $methodData['loc']; $classLoc += $methodData['loc'];
$classDloc += $methodData['dloc']; $classDloc += $methodData['dloc'];
@ -177,8 +184,10 @@
} }
$classStartLine = $refClass->getStartLine(); $classStartLine = $refClass->getStartLine();
$classCoverage .= "<tr class=\"class-coverage\"><th>&nbsp;&nbsp;<a href=\"#line-$classStartLine\">$class</a></th><td>$classCloc / " . ($classLoc - $classDloc) . "</td>"; $percentageData = self::getPercentage($classCloc, $classLoc - $classDloc);
$classCoverage .= "<td>" . round($classCloc / ($classLoc - $classDloc) * 100, 2) . "%</td></tr>\n"; $classCoverage .= "<tr class=\"class-coverage\"><th>&nbsp;&nbsp;<a href=\"#line-$classStartLine\">$class</a></th>";
$classCoverage .= "<td class=\"coverage-ratio\" style=\"background-color: $percentageData[1]\">$classCloc / " . ($classLoc - $classDloc) . "</td>";
$classCoverage .= "<td class=\"coverage-percentage\" style=\"background-color: $percentageData[1]\">$percentageData[0]%</td></tr>\n";
$classCoverage .= $methodCoverage; $classCoverage .= $methodCoverage;
} }
@ -186,8 +195,10 @@
$tdloc += $classData['procedural']['dloc']; $tdloc += $classData['procedural']['dloc'];
$tcloc += $classData['procedural']['cloc']; $tcloc += $classData['procedural']['cloc'];
$fileCoveragePercent = round($tcloc / max($tloc - $tdloc, 1) * 100, 2); $percentageData = self::getPercentage($tcloc, $tloc - $tdloc);
$fileCoverage = "<tr class=\"file-coverage\"><th>$sourceFile</th><td>$tcloc / " . ($tloc - $tdloc) . "</td><td>$fileCoveragePercent%</td></tr>\n"; $fileCoverage = "<tr class=\"file-coverage\"><th>$sourceFile</th>";
$fileCoverage .= "<td class=\"coverage-percentage\" style=\"background-color: $percentageData[1]\">$tcloc / " . ($tloc - $tdloc) . "</td>";
$fileCoverage .= "<td class=\"coverage-ratio\" style=\"background-color: $percentageData[1]\">$percentageData[0]%</td></tr>\n";
$fileCoverage .= $classCoverage; $fileCoverage .= $classCoverage;
unset($classCoverage, $methodCoverage, $classData, $refClass); unset($classCoverage, $methodCoverage, $classData, $refClass);
@ -197,7 +208,7 @@
$lineNumbers = ''; $lineNumbers = '';
for ($i = 1, $len = count($lines); $i <= $len; $i++) { for ($i = 1, $len = count($lines); $i <= $len; $i++) {
$lineNumbers .= '<div><a name="#line-' . $i . '" href="#line-' . $i . '">' . $i . '</a></div>'; $lineNumbers .= '<div><a name="line-' . $i . '" href="#line-' . $i . '">' . $i . '</a></div>';
$code .= '<div'; $code .= '<div';
if (isset($coverageData[$i])) { if (isset($coverageData[$i])) {
$code .= ' class="'; $code .= ' class="';
@ -239,7 +250,10 @@
'${product.name}', '${product.name}',
'${product.version}', '${product.version}',
'${product.website}', '${product.website}',
'${product.author}' '${product.author}',
'${php.version}',
'${xdebug.version}',
'${ezc.version}'
), ),
array( array(
Product::NAME . ' - Coverage Report', Product::NAME . ' - Coverage Report',
@ -251,7 +265,10 @@
Product::NAME, Product::NAME,
Product::VERSION, Product::VERSION,
Product::WEBSITE, Product::WEBSITE,
Product::AUTHOR Product::AUTHOR,
phpversion(),
phpversion('xdebug'),
Product::EZC_VERSION
), ),
$template $template
); );
@ -319,17 +336,19 @@
} }
$subdata = $dirData[$subdir]; $subdata = $dirData[$subdir];
$percentageData = self::getPercentage($subdata['cloc'], $subdata['loc'] - $subdata['dloc']);
$info .= '<tr><th><a href="' . self::buildLink($baseDir, $subdir . DIRECTORY_SEPARATOR . 'foo', true) . '.html">' . basename($subdir) . '</a></th>'; $info .= '<tr><th><a href="' . self::buildLink($baseDir, $subdir . DIRECTORY_SEPARATOR . 'foo', true) . '.html">' . basename($subdir) . '</a></th>';
$info .= '<td>' . $subdata['cloc'] . ' / ' . ($subdata['loc'] - $subdata['dloc']) . '</td>'; $info .= '<td class="coverage-ratio" style="background-color: ' . $percentageData[1] . '">' . $subdata['cloc'] . ' / ' . ($subdata['loc'] - $subdata['dloc']) . '</td>';
$info .= '<td>' . round($subdata['cloc'] / ($subdata['loc'] - $subdata['dloc']) * 100, 2) . '%</td>'; $info .= "<td class=\"coverage-percentage\" style=\"background-color: $percentageData[1]\">$percentageData[0]%</td>";
$info .= "</tr>\n"; $info .= "</tr>\n";
} }
//regular files in current directory //regular files in current directory
foreach ($data['files'] as $file => $fileData) { foreach ($data['files'] as $file => $fileData) {
$percentageData = self::getPercentage($fileData['cloc'], $fileData['loc'] - $fileData['dloc']);
$info .= '<tr><th><a href="' . self::buildLink($baseDir, $file, true) . '-' . basename($file) . '.html">' . basename($file) . '</a></th>'; $info .= '<tr><th><a href="' . self::buildLink($baseDir, $file, true) . '-' . basename($file) . '.html">' . basename($file) . '</a></th>';
$info .= '<td>' . $fileData['cloc'] . ' / ' . ($fileData['loc'] - $fileData['dloc']) . '</td>'; $info .= '<td class="coverage-ratio" style="background-color: ' . $percentageData[1] . '">' . $fileData['cloc'] . ' / ' . ($fileData['loc'] - $fileData['dloc']) . '</td>';
$info .= '<td>' . round($fileData['cloc'] / ($fileData['loc'] - $fileData['dloc']) * 100, 2) . '%</td>'; $info .= "<td class=\"coverage-percentage\" style=\"background-color: $percentageData[1]\">$percentageData[0]%</td>";
$info .= "</tr>\n"; $info .= "</tr>\n";
} }
@ -342,7 +361,10 @@
'${product.name}', '${product.name}',
'${product.version}', '${product.version}',
'${product.website}', '${product.website}',
'${product.author}' '${product.author}',
'${php.version}',
'${xdebug.version}',
'${ezc.version}'
), ),
array( array(
Product::NAME . ' - Coverage Report', Product::NAME . ' - Coverage Report',
@ -352,7 +374,10 @@
Product::NAME, Product::NAME,
Product::VERSION, Product::VERSION,
Product::WEBSITE, Product::WEBSITE,
Product::AUTHOR Product::AUTHOR,
phpversion(),
phpversion('xdebug'),
Product::EZC_VERSION
), ),
$template $template
); );
@ -368,6 +393,7 @@
} else { } else {
$link = '<a href="./index.html">' . $baseDir . '</a>'; $link = '<a href="./index.html">' . $baseDir . '</a>';
} }
$dirs = preg_split('@\\' . DIRECTORY_SEPARATOR . '@', str_replace($baseDir, '', dirname($path) . DIRECTORY_SEPARATOR), -1, PREG_SPLIT_NO_EMPTY); $dirs = preg_split('@\\' . DIRECTORY_SEPARATOR . '@', str_replace($baseDir, '', dirname($path) . DIRECTORY_SEPARATOR), -1, PREG_SPLIT_NO_EMPTY);
$path = ''; $path = '';
foreach ($dirs as $dir) { foreach ($dirs as $dir) {
@ -376,6 +402,7 @@
} else { } else {
$path = $path . '-' . $dir; $path = $path . '-' . $dir;
} }
if ($oneLink) { if ($oneLink) {
$link = $path; $link = $path;
} else { } else {
@ -394,6 +421,25 @@
return $old + (($new > 0) ? 1 : 0); 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('&nbsp;', 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;
}
} }
?> ?>

View File

@ -13,18 +13,32 @@
<div id="wrapper"> <div id="wrapper">
<div id="header"> <div id="header">
<h1>${file.link}</h1> <h1>${product.name} Code Coverage Report</h1>
</div>
<div id="file-link">
<p>${file.link}</p>
</div> </div>
<div id="directory-coverage"> <div id="directory-coverage">
<table> <table>
<colgroup>
<col style="width:50%"/>
<col style="width:25%"/>
<col style="width:25%"/>
</colgroup>
${directory.coverage} ${directory.coverage}
</table> </table>
</div> </div>
<div id="footer"> <div id="footer">
<p> <p>
Generated on ${timestamp} by <a href="${product.website}">${product.name} ${product.version}</a> Generated on ${timestamp} by <a href="${product.website}" title="${product.name}">${product.name} ${product.version}</a>
<br />
<a href="http://php.net/" title="PHP">PHP ${php.version}</a> |
<a href="http://xdebug.org/" title="Xdebug">Xdebug ${xdebug.version}</a> |
<a href="http://ezcomponents.org/" title="ezComponents">ezComponents ${ezc.version}</a>
<br /> <br />
&copy; 2009 ${product.author} &copy; 2009 ${product.author}
</p> </p>

View File

@ -13,14 +13,25 @@
<div id="wrapper"> <div id="wrapper">
<div id="header"> <div id="header">
<h1>${file.link}</h1> <h1>${product.name} Code Coverage Report</h1>
</div>
<div id="file-link">
<p>${file.link}</p>
</div> </div>
<div id="summary"> <div id="summary">
<table> <table>
<tr> <colgroup>
<td></td><th colspan="3">Coverage</th> <col width="50%"/>
</tr> <col width="25%"/>
<col width="25%"/>
</colgroup>
<thead>
<tr>
<td></td><th colspan="2">Coverage</th>
</tr>
</thead>
${file.coverage} ${file.coverage}
</table> </table>
</div> </div>
@ -36,7 +47,11 @@ ${code}
<div id="footer"> <div id="footer">
<p> <p>
Generated on ${timestamp} by <a href="${product.website}">${product.name} ${product.version}</a> Generated on ${timestamp} by <a href="${product.website}" title="${product.name}">${product.name} ${product.version}</a>
<br />
<a href="http://php.net/" title="PHP">PHP ${php.version}</a> |
<a href="http://xdebug.org/" title="Xdebug">Xdebug ${xdebug.version}</a> |
<a href="http://ezcomponents.org/" title="ezComponents">ezComponents ${ezc.version}</a>
<br /> <br />
&copy; 2009 ${product.author} &copy; 2009 ${product.author}
</p> </p>

View File

@ -2,11 +2,48 @@ html {
overflow: auto; overflow: auto;
} }
body { body {
background-color: #FFFFCC; background-color: #CCFFCC;
color: #000000; color: #000000;
font-family: Consolas, "Courier New", monospace; font-family: Consolas, "Courier New", monospace;
font-size: 16px; font-size: 16px;
} }
h1 {
text-align: center;
}
a {
text-decoration: none;
color: #990099;
}
a:hover {
text-decoration: underline;
}
table {
background-color: #FFFFFF;
border-collapse: collapse;
border: 2px solid #000000;
width: 100%;
}
th, td {
border: 1px solid #000000;
padding: .3em;
}
th {
text-align: left;
font-weight: bold;
}
thead th {
text-align: center;
}
#file-link {
text-align: center;
}
#file-link a {
color: #990000;
display: inline-block;
margin-right: 5px;
font-weight: bold;
}
#code-wrapper { #code-wrapper {
background-color: #FFFFFF; background-color: #FFFFFF;
@ -42,16 +79,21 @@ body {
background-color: #FFFFFF; background-color: #FFFFFF;
margin-bottom: 20px; margin-bottom: 20px;
} }
#summary th {
text-align: left;
}
#footer { #footer {
text-align: center; text-align: center;
font-family: Verdana, sans-serif; font-size: 12px;
font-size: 8pt; }
#footer a {
color: #000000;
} }
.coverage-percentage {
text-align: center;
}
.coverage-ratio {
text-align: center;
}
.covered { .covered {
background-color: #66FF66; background-color: #66FF66;
} }

View File

@ -75,7 +75,7 @@
$paramList = ''; $paramList = '';
foreach ($method->getParameters() as $i => $param) { foreach ($method->getParameters() as $i => $param) {
if ($param->getClass()) { if ($param->getClass()) {
$paramList .= $param->getClass() . ' '; $paramList .= $param->getClass()->getName() . ' ';
} else if ($param->isArray()) { } else if ($param->isArray()) {
$paramList .= 'array '; $paramList .= 'array ';
} }
@ -89,13 +89,18 @@
if ($param->isOptional()) { if ($param->isOptional()) {
$paramList .= ' = '; $paramList .= ' = ';
if ($param->isDefaultValueAvailable()) { if ($param->isDefaultValueAvailable()) {
$paramList .= var_export($param->getDefaultValue(), true); if (is_array($param->getDefaultValue())) {
//removes annoying spaces in parens
$paramList .= 'array()';
} else {
$paramList .= var_export($param->getDefaultValue(), true);
}
} else { } else {
$paramList .= 'null'; $paramList .= 'null';
} }
} }
$paramList .= ','; $paramList .= ', ';
} }
return rtrim($paramList, ', '); return rtrim($paramList, ', ');

View File

@ -26,6 +26,7 @@
->addSwitch(new CliSwitch('version', 'v', true, 'version_number', 'Product version')) ->addSwitch(new CliSwitch('version', 'v', true, 'version_number', 'Product version'))
->addSwitch(new CliSwitch('author', 'a', true, 'author_name', 'Product author')) ->addSwitch(new CliSwitch('author', 'a', true, 'author_name', 'Product author'))
->addSwitch(new CliSwitch('website', 'w', true, 'url', 'Product website')) ->addSwitch(new CliSwitch('website', 'w', true, 'url', 'Product website'))
->addSwitch(new CliSwitch('ezc', 'e', true, 'version', 'ezComponents version number'))
->addSwitch(new CliSwitch('package', 'p', true, 'package_name ', 'Name of the package for use in @package tag')) ->addSwitch(new CliSwitch('package', 'p', true, 'package_name ', 'Name of the package for use in @package tag'))
->addSwitch(new CliSwitch('doc-version', 'd', false, 'version_number', 'Version number for use in @version tag')) ->addSwitch(new CliSwitch('doc-version', 'd', false, 'version_number', 'Version number for use in @version tag'))
->addSwitch(new CliSwitch('output', 'o', false, 'file|dir', 'The file/directory to write the generated class to; default is stdout')); ->addSwitch(new CliSwitch('output', 'o', false, 'file|dir', 'The file/directory to write the generated class to; default is stdout'));
@ -76,27 +77,32 @@
/** /**
* Product name * Product name
*/ */
const NAME = '$args[name]'; const NAME = '$args[name]';
/** /**
* Product version * Product version
*/ */
const VERSION = '$args[version]'; const VERSION = '$args[version]';
/** /**
* Product author * Product author
*/ */
const AUTHOR = '$args[author]'; const AUTHOR = '$args[author]';
/** /**
* Product website * Product website
*/ */
const WEBSITE = '$args[website]'; const WEBSITE = '$args[website]';
/** /**
* Product build date * Product build date
*/ */
const DATE = '$datetime'; const DATE = '$datetime';
/**
* ezComponents version
*/
const EZC_VERSION = '$args[ezc]';
/**#@-*/ /**#@-*/
/** /**