From: Tim Otten Date: Tue, 26 Aug 2014 20:58:09 +0000 (-0700) Subject: phpunit-compare - Add support for CSV output X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=dc34d722d8ca7d6824d53f60499029a92cecb1f0;p=civicrm-core.git phpunit-compare - Add support for CSV output --- diff --git a/Civi/CiUtil/Command/CompareCommand.php b/Civi/CiUtil/Command/CompareCommand.php index 44ee0dac2a..4e22e6788a 100644 --- a/Civi/CiUtil/Command/CompareCommand.php +++ b/Civi/CiUtil/Command/CompareCommand.php @@ -5,11 +5,12 @@ class CompareCommand { static function main($argv) { if (empty($argv[1])) { echo "summary: Compares the output of different test runs\n"; - echo "usage: phpunit-compare [--phpunit-json|--jenkins-xml] ...\n"; + echo "usage: phpunit-compare [--out=txt|csv] [--phpunit-json|--jenkins-xml] ...\n"; exit(1); } $parser = array('\Civi\CiUtil\PHPUnitParser', 'parseJsonResults'); + $printerType = 'txt'; $suites = array(); // array('file' => string, 'results' => array) for ($i = 1; $i < count($argv); $i++) { switch ($argv[$i]) { @@ -19,6 +20,12 @@ class CompareCommand { case '--jenkins-xml': $parser = array('\Civi\CiUtil\JenkinsParser', 'parseXmlResults'); break; + case '--out=txt': + $printerType = 'txt'; + break; + case '--out=csv': + $printerType = 'csv'; + break; default: $suites[] = array( 'file' => $argv[$i], @@ -36,7 +43,11 @@ class CompareCommand { } sort($tests); - $printer = new \Civi\CiUtil\ComparisonPrinter(\Civi\CiUtil\Arrays::collect($suites, 'file')); + if ($printerType == 'csv') { + $printer = new \Civi\CiUtil\CsvPrinter('php://stdout', \Civi\CiUtil\Arrays::collect($suites, 'file')); + } else { + $printer = new \Civi\CiUtil\ComparisonPrinter(\Civi\CiUtil\Arrays::collect($suites, 'file')); + } foreach ($tests as $test) { $values = array(); foreach ($suites as $suite) { diff --git a/Civi/CiUtil/CsvPrinter.php b/Civi/CiUtil/CsvPrinter.php new file mode 100644 index 0000000000..9cab44a90f --- /dev/null +++ b/Civi/CiUtil/CsvPrinter.php @@ -0,0 +1,32 @@ +file = fopen($file, "w"); + $this->headers = $headers; + } + + function printHeader() { + if ($this->hasHeader) { + return; + } + + $headers = array_values($this->headers); + array_unshift($headers, 'TEST NAME'); + fputcsv($this->file, $headers); + + $this->hasHeader = TRUE; + } + + function printRow($test, $values) { + $this->printHeader(); + $row = $values; + array_unshift($row, $test); + fputcsv($this->file, $row); + } +} \ No newline at end of file