fixed a couple bugs in code coverage gathering; renamed tunit.js to testify.js

This commit is contained in:
tmont 2009-07-01 10:02:44 +00:00
parent 3c27ef31f4
commit 725d847ce9
6 changed files with 21 additions and 16 deletions

View File

@ -19,12 +19,22 @@
$refClasses[] = new ReflectionClass($class); $refClasses[] = new ReflectionClass($class);
} }
$newData[$file] = array();
$newData[$file] = array(
'classes' => array(),
'procedural' => array(
'loc' => 0,
'dloc' => 0,
'cloc' => 0
)
);
foreach ($data as $line => $unitsCovered) { foreach ($data as $line => $unitsCovered) {
$loc = 1; $loc = 1;
$dloc = ($unitsCovered === self::DEAD) ? 1 : 0; $dloc = ($unitsCovered === self::DEAD) ? 1 : 0;
$cloc = ($unitsCovered > 0) ? 1 : 0; $cloc = ($unitsCovered > 0) ? 1 : 0;
//find the class this line resides in, if any //find the class this line resides in, if any
$class = null; $class = null;
foreach ($refClasses as $refClass) { foreach ($refClasses as $refClass) {
@ -54,17 +64,9 @@
//procedural code //procedural code
if ($class === null) { if ($class === null) {
if (isset($newData[$file]['procedural'])) { $newData[$file]['procedural']['loc'] += $loc;
$newData[$file]['procedural']['loc'] += $loc; $newData[$file]['procedural']['dloc'] += $dloc;
$newData[$file]['procedural']['dloc'] += $dloc; $newData[$file]['procedural']['cloc'] += $cloc;
$newData[$file]['procedural']['cloc'] += $cloc;
} else {
$newData[$file]['procedural'] = array(
'loc' => $loc,
'dloc' => $dloc,
'cloc' => $cloc
);
}
} }
} }
} }
@ -143,7 +145,7 @@
//copy css over //copy css over
$template = dirname(__FILE__) . DIRECTORY_SEPARATOR . self::TEMPLATE_DIR . DIRECTORY_SEPARATOR; $template = dirname(__FILE__) . DIRECTORY_SEPARATOR . self::TEMPLATE_DIR . DIRECTORY_SEPARATOR;
copy($template . 'style.css', $coverageDir . DIRECTORY_SEPARATOR . 'style.css'); copy($template . 'style.css', $coverageDir . DIRECTORY_SEPARATOR . 'style.css');
copy($template . 'Testify.js', $coverageDir . DIRECTORY_SEPARATOR . 'Testify.js'); copy($template . 'testify.js', $coverageDir . DIRECTORY_SEPARATOR . 'testify.js');
} }
private static function writeHtmlFile($sourceFile, $baseDir, $coverageDir, array $classData, array $coverageData, $renderer) { private static function writeHtmlFile($sourceFile, $baseDir, $coverageDir, array $classData, array $coverageData, $renderer) {

View File

@ -6,7 +6,7 @@
<title>${title}</title> <title>${title}</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/> <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" href="./style.css"/> <link rel="stylesheet" type="text/css" href="./style.css"/>
<script type="text/javascript" src="./Testify.js"></script> <script type="text/javascript" src="./testify.js"></script>
</head> </head>
<body> <body>

View File

@ -6,7 +6,7 @@
<title>${title}</title> <title>${title}</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/> <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" href="./style.css"/> <link rel="stylesheet" type="text/css" href="./style.css"/>
<script type="text/javascript" src="./Testify.js"></script> <script type="text/javascript" src="./testify.js"></script>
</head> </head>
<body> <body>

View File

@ -106,7 +106,7 @@
require_once $file; require_once $file;
$ref = new ReflectionClass($className); $ref = new ReflectionClass($className);
if ($ref->isSubClassOf('TestCase')) { if ($ref->implementsInterface('Testable') && $ref->isInstantiable()) {
$tests[] = $ref->newInstance($className); $tests[] = $ref->newInstance($className);
//add to filter //add to filter
CoverageFilter::addFile($file); CoverageFilter::addFile($file);

View File

@ -254,6 +254,9 @@
} }
public static function getClassNamesFromFile($file) { public static function getClassNamesFromFile($file) {
if (!is_file($file)) {
return array();
}
$tokens = token_get_all(file_get_contents($file)); $tokens = token_get_all(file_get_contents($file));
$classes = array(); $classes = array();
for ($i = 0, $len = count($tokens); $i < $len; $i++) { for ($i = 0, $len = count($tokens); $i < $len; $i++) {