phpunit-compare - Add support for CSV output
[civicrm-core.git] / Civi / CiUtil / Command / CompareCommand.php
index 44ee0dac2ad8466a21ec50450e0d031c97758859..4e22e6788a16e94e4db32791145598453af9fec8 100644 (file)
@@ -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] <file1> <file2>...\n";
+      echo "usage: phpunit-compare [--out=txt|csv] [--phpunit-json|--jenkins-xml] <file1> <file2>...\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) {