diff --git a/src/TUnit/framework/reporting/CoverageReporter.php b/src/TUnit/framework/reporting/CoverageReporter.php index edda748..98a0723 100644 --- a/src/TUnit/framework/reporting/CoverageReporter.php +++ b/src/TUnit/framework/reporting/CoverageReporter.php @@ -108,13 +108,14 @@ fwrite(STDOUT, "Totals:\n"); fwrite(STDOUT, " Covered: $totcloc\n"); fwrite(STDOUT, " Dead: $totdloc\n"); - fwrite(STDOUT, " Executable: " . ($totloc - $totdloc) . "" . round($totcloc / ($totloc - $dloc) * 100, 2) . "%)\n"); + fwrite(STDOUT, " Executable: " . ($totloc - $totdloc) . " (" . round($totcloc / ($totloc - $dloc) * 100, 2) . "%)\n"); } public static function createHtmlReport($coverageDir, array $coverageData) { $coverageData = CoverageFilter::filter($coverageData); $baseDir = array(); + $dirData = array(); foreach ($coverageData as $file => $data) { $dirs = explode(DIRECTORY_SEPARATOR, dirname($file)); if (empty($baseDir)) { @@ -134,12 +135,11 @@ $classData = self::parseCoverageData($coverageData); - $dirData = array(); foreach ($coverageData as $file => $data) { self::writeHtmlFile($file, $baseDir, $coverageDir, $classData[$file], $data); } - self::writeHtmlDirectories($coverageDir, $baseDir, $classData); + self::writeHtmlDirectories($coverageDir, $baseDir, $coverageData); //copy css over $template = dirname(__FILE__) . DIRECTORY_SEPARATOR . self::TEMPLATE_DIR . DIRECTORY_SEPARATOR; @@ -222,16 +222,10 @@ } unset($lines); - $fileName = str_replace(array($baseDir, DIRECTORY_SEPARATOR), array('', '_'), $sourceFile); + $fileName = '-' . str_replace(array($baseDir, DIRECTORY_SEPARATOR), array('', '-'), $sourceFile); $newFile = $coverageDir . DIRECTORY_SEPARATOR . $fileName . '.html'; - $link = '' . $baseDir . ''; - $dirs = preg_split('@\\' . DIRECTORY_SEPARATOR . '@', str_replace($baseDir, '', dirname($sourceFile) . DIRECTORY_SEPARATOR), -1, PREG_SPLIT_NO_EMPTY); - $path = ''; - foreach ($dirs as $dir) { - $path = ltrim($path . '_' . $dir, '_'); - $link .= '' . $dir . '' . DIRECTORY_SEPARATOR; - } + $link = self::buildLink($baseDir, $sourceFile); $template = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . self::TEMPLATE_DIR . DIRECTORY_SEPARATOR . 'file.html'); $template = str_replace( @@ -265,8 +259,134 @@ return file_put_contents($newFile, $template); } - private static function writeHtmlDirectories($coverageDir, $baseDir, array $classData) { + private static function writeHtmlDirectories($coverageDir, $baseDir, array $coverageData) { + $dirData = array(); + foreach ($coverageData as $file => $data) { + $dirs = preg_split('@\\' . DIRECTORY_SEPARATOR . '@', str_replace($baseDir, '', dirname($file) . DIRECTORY_SEPARATOR), -1, PREG_SPLIT_NO_EMPTY); + if (empty($dirs)) { + continue; + } + + $loc = count($data); + $dloc = array_reduce($data, 'CoverageReporter::getDeadLoc', 0); + $cloc = array_reduce($data, 'CoverageReporter::getCoveredLoc', 0); + + $index = ''; + foreach ($dirs as $dir) { + $index .= DIRECTORY_SEPARATOR . $dir; + if (!isset($dirData[$index])) { + $dirData[$index] = array( + 'loc' => $loc, + 'dloc' => $dloc, + 'cloc' => $cloc, + 'files' => array() + ); + } else { + $dirData[$index]['loc'] += $loc; + $dirData[$index]['dloc'] += $dloc; + $dirData[$index]['cloc'] += $cloc; + } + } + + $dirData[DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $dirs)]['files'][$file] = array( + 'loc' => $loc, + 'dloc' => $dloc, + 'cloc' => $cloc + ); + } + $template = dirname(__FILE__) . DIRECTORY_SEPARATOR . self::TEMPLATE_DIR . DIRECTORY_SEPARATOR . 'directory.html'; + $template = file_get_contents($template); + + foreach ($dirData as $dir => $data) { + $info = ''; + $link = ''; + $subdirs = array(); + foreach ($dirData as $dir2 => $data2) { + if (substr($dir2, 0, strrpos($dir2, DIRECTORY_SEPARATOR)) === $dir) { + //this is a direct subdirectory + $subdirs[] = $dir2; + } + } + + sort($subdirs); + + //create directory info + foreach ($subdirs as $subdir) { + $subdata = $dirData[$subdir]; + + $info .= '