From 725d847ce98acc07455b49155ccba97519d61d33 Mon Sep 17 00:00:00 2001 From: tmont Date: Wed, 1 Jul 2009 10:02:44 +0000 Subject: [PATCH] fixed a couple bugs in code coverage gathering; renamed tunit.js to testify.js --- .../framework/reporting/CoverageReporter.php | 28 ++++++++++--------- .../reporting/template/directory.html | 2 +- .../framework/reporting/template/file.html | 2 +- .../template/{tunit.js => testify.js} | 0 src/Testify/util/TestAccumulator.php | 2 +- src/Testify/util/Util.php | 3 ++ 6 files changed, 21 insertions(+), 16 deletions(-) rename src/Testify/framework/reporting/template/{tunit.js => testify.js} (100%) diff --git a/src/Testify/framework/reporting/CoverageReporter.php b/src/Testify/framework/reporting/CoverageReporter.php index c19cdcf..15feeb3 100644 --- a/src/Testify/framework/reporting/CoverageReporter.php +++ b/src/Testify/framework/reporting/CoverageReporter.php @@ -19,12 +19,22 @@ $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) { $loc = 1; $dloc = ($unitsCovered === self::DEAD) ? 1 : 0; $cloc = ($unitsCovered > 0) ? 1 : 0; + + //find the class this line resides in, if any $class = null; foreach ($refClasses as $refClass) { @@ -54,17 +64,9 @@ //procedural code if ($class === null) { - if (isset($newData[$file]['procedural'])) { - $newData[$file]['procedural']['loc'] += $loc; - $newData[$file]['procedural']['dloc'] += $dloc; - $newData[$file]['procedural']['cloc'] += $cloc; - } else { - $newData[$file]['procedural'] = array( - 'loc' => $loc, - 'dloc' => $dloc, - 'cloc' => $cloc - ); - } + $newData[$file]['procedural']['loc'] += $loc; + $newData[$file]['procedural']['dloc'] += $dloc; + $newData[$file]['procedural']['cloc'] += $cloc; } } } @@ -143,7 +145,7 @@ //copy css over $template = dirname(__FILE__) . DIRECTORY_SEPARATOR . self::TEMPLATE_DIR . DIRECTORY_SEPARATOR; 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) { diff --git a/src/Testify/framework/reporting/template/directory.html b/src/Testify/framework/reporting/template/directory.html index df38930..11dadc3 100644 --- a/src/Testify/framework/reporting/template/directory.html +++ b/src/Testify/framework/reporting/template/directory.html @@ -6,7 +6,7 @@ ${title} - + diff --git a/src/Testify/framework/reporting/template/file.html b/src/Testify/framework/reporting/template/file.html index 52d8271..2757b06 100644 --- a/src/Testify/framework/reporting/template/file.html +++ b/src/Testify/framework/reporting/template/file.html @@ -6,7 +6,7 @@ ${title} - + diff --git a/src/Testify/framework/reporting/template/tunit.js b/src/Testify/framework/reporting/template/testify.js similarity index 100% rename from src/Testify/framework/reporting/template/tunit.js rename to src/Testify/framework/reporting/template/testify.js diff --git a/src/Testify/util/TestAccumulator.php b/src/Testify/util/TestAccumulator.php index c7877ed..d0030f7 100644 --- a/src/Testify/util/TestAccumulator.php +++ b/src/Testify/util/TestAccumulator.php @@ -106,7 +106,7 @@ require_once $file; $ref = new ReflectionClass($className); - if ($ref->isSubClassOf('TestCase')) { + if ($ref->implementsInterface('Testable') && $ref->isInstantiable()) { $tests[] = $ref->newInstance($className); //add to filter CoverageFilter::addFile($file); diff --git a/src/Testify/util/Util.php b/src/Testify/util/Util.php index 5fd5118..88987c3 100644 --- a/src/Testify/util/Util.php +++ b/src/Testify/util/Util.php @@ -254,6 +254,9 @@ } public static function getClassNamesFromFile($file) { + if (!is_file($file)) { + return array(); + } $tokens = token_get_all(file_get_contents($file)); $classes = array(); for ($i = 0, $len = count($tokens); $i < $len; $i++) {