diff --git a/src/TUnit/framework/ConsoleTestRunner.php b/src/TUnit/framework/ConsoleTestRunner.php index b7c7822..4202ce5 100644 --- a/src/TUnit/framework/ConsoleTestRunner.php +++ b/src/TUnit/framework/ConsoleTestRunner.php @@ -96,14 +96,14 @@ protected function postRun() { $html = $this->getOption('coverage-html'); $console = $this->getOption('coverage-console'); - if ($html || $console) { + if ($html !== null || $console === true) { $coverage = xdebug_get_code_coverage(); xdebug_stop_code_coverage(); - if ($console !== null) { + if ($console === true) { CoverageReporter::createConsoleReport($coverage); } if ($html !== null) { - CoverageReporter::createHtmlReport($html, $coverage); + CoverageReporter::createHtmlReport($html, $coverage, $this->getOption('coverage-renderer')); } unset($coverage); @@ -171,6 +171,13 @@ throw new TUnitException('Could not create directory: ' . $options['coverage-html']); } } + + //check the renderer + if ($options['coverage-renderer'] !== null) { + if (!in_array($options['coverage-renderer'], array('png'))) { + throw new InvalidOptionException('coverage-renderer', 'unknown renderer: ' . $options['renderer']); + } + } } } } @@ -186,11 +193,11 @@ */ public function getAllowableOptions() { return array( - 'bootstrap' => null, - 'recursive' => false, - //'coverage-xml' => null, - 'coverage-html' => null, - 'coverage-console' => false + 'bootstrap' => null, + 'recursive' => false, + 'coverage-html' => null, + 'coverage-renderer' => null, + 'coverage-console' => false ); } diff --git a/src/TUnit/framework/reporting/CoveragePieChart.php b/src/TUnit/framework/reporting/CoverageGraphs.php similarity index 97% rename from src/TUnit/framework/reporting/CoveragePieChart.php rename to src/TUnit/framework/reporting/CoverageGraphs.php index 7a1991b..cfedefb 100644 --- a/src/TUnit/framework/reporting/CoveragePieChart.php +++ b/src/TUnit/framework/reporting/CoverageGraphs.php @@ -40,7 +40,7 @@ class CoveragePieChart extends ezcGraphPieChart { - public function __construct() { + public function __construct($renderer) { parent::__construct(); $this->palette = new CoveragePalette(); @@ -50,6 +50,7 @@ $this->options->label = '%2$s (%3$.1f%%)'; $this->legend->position = ezcGraph::BOTTOM; + //use renderer here... $this->renderer = new CoverageRenderer(); $this->renderer->options->pieChartRotation = .6; diff --git a/src/TUnit/framework/reporting/CoverageReporter.php b/src/TUnit/framework/reporting/CoverageReporter.php index 28c72a2..b9ae007 100644 --- a/src/TUnit/framework/reporting/CoverageReporter.php +++ b/src/TUnit/framework/reporting/CoverageReporter.php @@ -110,7 +110,7 @@ fwrite(STDOUT, " Executable: " . ($totloc - $totdloc) . " (" . round($totcloc / ($totloc - $dloc) * 100, 2) . "%)\n"); } - public static function createHtmlReport($coverageDir, array $coverageData) { + public static function createHtmlReport($coverageDir, array $coverageData, $renderer = null) { $coverageData = CoverageFilter::filter($coverageData); $baseDir = array(); @@ -135,10 +135,10 @@ $classData = self::parseCoverageData($coverageData); foreach ($coverageData as $file => $data) { - self::writeHtmlFile($file, $baseDir, $coverageDir, $classData[$file], $data); + self::writeHtmlFile($file, $baseDir, $coverageDir, $classData[$file], $data, $renderer); } - self::writeHtmlDirectories($coverageDir, $baseDir, $coverageData); + self::writeHtmlDirectories($coverageDir, $baseDir, $coverageData, $renderer); //copy css over $template = dirname(__FILE__) . DIRECTORY_SEPARATOR . self::TEMPLATE_DIR . DIRECTORY_SEPARATOR; @@ -146,7 +146,7 @@ copy($template . 'tunit.js', $coverageDir . DIRECTORY_SEPARATOR . 'tunit.js'); } - private static function writeHtmlFile($sourceFile, $baseDir, $coverageDir, array $classData, array $coverageData) { + private static function writeHtmlFile($sourceFile, $baseDir, $coverageDir, array $classData, array $coverageData, $renderer) { //summary view $fileCoverage = ''; $classCoverage = ''; @@ -178,7 +178,9 @@ $methodCoverage .= "    $methodDeclaration"; $methodCoverage .= "$methodData[cloc] / " . ($methodData['loc'] - $methodData['dloc']) . ""; $methodCoverage .= "$percentageData[0]%\n"; - $methodCoverage .= 'Code Coverage results'; + if ($renderer !== null) { + $methodCoverage .= 'Code Coverage results'; + } $classLoc += $methodData['loc']; $classDloc += $methodData['dloc']; @@ -190,7 +192,9 @@ $classCoverage .= "  $class"; $classCoverage .= "$classCloc / " . ($classLoc - $classDloc) . ""; $classCoverage .= "$percentageData[0]%\n"; - $classCoverage .= 'Code Coverage results'; + if ($renderer !== null) { + $classCoverage .= 'Code Coverage results'; + } $classCoverage .= $methodCoverage; } @@ -202,7 +206,9 @@ $fileCoverage = "$sourceFile"; $fileCoverage .= "$tcloc / " . ($tloc - $tdloc) . ""; $fileCoverage .= "$percentageData[0]%\n"; - $fileCoverage .= 'Code Coverage results'; + if ($renderer !== null) { + $fileCoverage .= 'Code Coverage results'; + } $fileCoverage .= $classCoverage; unset($classCoverage, $methodCoverage, $classData, $refClass); @@ -280,7 +286,7 @@ return file_put_contents($newFile, $template); } - private static function writeHtmlDirectories($coverageDir, $baseDir, array $coverageData) { + private static function writeHtmlDirectories($coverageDir, $baseDir, array $coverageData, $renderer) { $dirData = array(); foreach ($coverageData as $file => $data) { $dirs = preg_split('@\\' . DIRECTORY_SEPARATOR . '@', str_replace($baseDir, '', dirname($file) . DIRECTORY_SEPARATOR), -1, PREG_SPLIT_NO_EMPTY); @@ -345,7 +351,9 @@ $info .= '' . $subdata['cloc'] . ' / ' . ($subdata['loc'] - $subdata['dloc']) . ''; $info .= "$percentageData[0]%"; $info .= "\n"; - $info .= 'Code Coverage results'; + if ($renderer !== null) { + $info .= 'Code Coverage results'; + } } //regular files in current directory @@ -355,7 +363,9 @@ $info .= '' . $fileData['cloc'] . ' / ' . ($fileData['loc'] - $fileData['dloc']) . ''; $info .= "$percentageData[0]%"; $info .= "\n"; - $info .= 'Code Coverage results'; + if ($renderer !== null) { + $info .= 'Code Coverage results'; + } } $temp = str_replace( @@ -446,8 +456,8 @@ return $color; } - private static function getDataUri($loc, $dloc, $cloc) { - $graph = new CoveragePieChart(); + private static function getDataUri($loc, $dloc, $cloc, $renderer) { + $graph = new CoveragePieChart($renderer); return $graph->renderToDataUri(300, 225, $loc - $cloc - $dloc, $dloc, $cloc); } diff --git a/src/TUnit/manifest.php b/src/TUnit/manifest.php index 6e6cf42..62a1db5 100644 --- a/src/TUnit/manifest.php +++ b/src/TUnit/manifest.php @@ -3,7 +3,7 @@ /** * Autoload manifest * - * Autogenerated by manifester.php on 2009-06-30 20:59:11 + * Autogenerated by manifester.php on 2009-06-30 23:05:13 * * @package TUnit * @version 0.5.0 @@ -20,11 +20,11 @@ 'ConsoleListener' => 'TUnit/framework/listeners/ConsoleListener.php', 'ConsoleTestRunner' => 'TUnit/framework/ConsoleTestRunner.php', 'Constraint' => 'TUnit/framework/constraints/Constraint.php', - 'CoverageDriver' => 'TUnit/framework/reporting/CoveragePieChart.php', + 'CoverageDriver' => 'TUnit/framework/reporting/CoverageGraphs.php', 'CoverageFilter' => 'TUnit/framework/reporting/CoverageFilter.php', - 'CoveragePalette' => 'TUnit/framework/reporting/CoveragePieChart.php', - 'CoveragePieChart' => 'TUnit/framework/reporting/CoveragePieChart.php', - 'CoverageRenderer' => 'TUnit/framework/reporting/CoveragePieChart.php', + 'CoveragePalette' => 'TUnit/framework/reporting/CoverageGraphs.php', + 'CoveragePieChart' => 'TUnit/framework/reporting/CoverageGraphs.php', + 'CoverageRenderer' => 'TUnit/framework/reporting/CoverageGraphs.php', 'CoverageReporter' => 'TUnit/framework/reporting/CoverageReporter.php', 'DefaultConstraint' => 'TUnit/framework/constraints/DefaultConstraint.php', 'EmptyConstraint' => 'TUnit/framework/constraints/SimpleConstraints.php', diff --git a/src/TUnit/util/entry_console.php b/src/TUnit/util/entry_console.php index 75c5299..662e9e4 100644 --- a/src/TUnit/util/entry_console.php +++ b/src/TUnit/util/entry_console.php @@ -43,14 +43,14 @@ global $switches; $switches = new CliSwitchCollection(); - $switches->addSwitch(new CliSwitch(null, null, true, '', 'Files and/or directories to parse for test cases')) - ->addSwitch(new CliSwitch('help', 'h', false, null, 'Display this help message (also --usage)')) - ->addSwitch(new CliSwitch('usage', null, false, null, 'Display this help message')) - ->addSwitch(new CliSwitch('recursive', null, false, null, 'Recurse into subdirectories')) - ->addSwitch(new CliSwitch('bootstrap', 'b', false, 'file', 'File to include before tests are run')) - //->addSwitch(new CliSwitch('coverage-xml', null, false, 'file', 'Generate code coverage report in XML clover format (requires xdebug)')) - ->addSwitch(new CliSwitch('coverage-html', null, false, 'dir', 'Generate code coverage report in HTML (requires xdebug, optionally uses ezComponents)')) - ->addSwitch(new CliSwitch('coverage-console', null, false, null, 'Generate code coverage report suitable for console viewing')); + $switches->addSwitch(new CliSwitch(null, null, true, '', 'Files and/or directories to parse for test cases')) + ->addSwitch(new CliSwitch('help', 'h', false, null, 'Display this help message (also --usage)')) + ->addSwitch(new CliSwitch('usage', null, false, null, 'Display this help message')) + ->addSwitch(new CliSwitch('recursive', null, false, null, 'Recurse into subdirectories')) + ->addSwitch(new CliSwitch('bootstrap', 'b', false, 'file', 'File to include before tests are run')) + ->addSwitch(new CliSwitch('coverage-html', null, false, 'dir', 'Generate code coverage report in HTML (requires xdebug, optionally uses ezComponents)')) + ->addSwitch(new CliSwitch('coverage-renderer', null, false, 'type', 'Use with coverage-html to render code coverage graphs; png is the only type supported right now')) + ->addSwitch(new CliSwitch('coverage-console', null, false, null, 'Generate code coverage report suitable for console viewing')); array_shift($argv); $args = Cli::parseArgs($argv, $switches);