From dc34d722d8ca7d6824d53f60499029a92cecb1f0 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 26 Aug 2014 13:58:09 -0700 Subject: [PATCH] phpunit-compare - Add support for CSV output --- Civi/CiUtil/Command/CompareCommand.php | 15 ++++++++++-- Civi/CiUtil/CsvPrinter.php | 32 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 Civi/CiUtil/CsvPrinter.php 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 -- 2.25.1