phpunit-compare - Add support for reading results from CSV
authorTim Otten <totten@civicrm.org>
Thu, 4 Sep 2014 00:53:38 +0000 (17:53 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 4 Sep 2014 05:58:55 +0000 (22:58 -0700)
Civi/CiUtil/CSVParser.php [new file with mode: 0644]
Civi/CiUtil/Command/CompareCommand.php

diff --git a/Civi/CiUtil/CSVParser.php b/Civi/CiUtil/CSVParser.php
new file mode 100644 (file)
index 0000000..dc2196e
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+namespace Civi\CiUtil;
+
+/**
+ * Parse phpunit result files
+ */
+class CSVParser {
+
+  /**
+   * @param string $csvContent content; each row in the row csv should start with two cells:
+   *   - cell 0: the test name
+   *   - cell 1: the test status
+   * @return array (string $testName => string $status)
+   */
+  public static function parseResults($csvContent) {
+    $fh = fopen('php://memory', 'r+');
+    fwrite($fh, $csvContent);
+    rewind($fh);
+
+    $results = array();
+    while (($r = fgetcsv($fh)) !== FALSE) {
+      $name = str_replace('.', '::', trim($r[0]));
+      $status = trim($r[1]);
+      $results[$name] = $status;
+    }
+
+    return $results;
+  }
+
+}
\ No newline at end of file
index 4e22e6788a16e94e4db32791145598453af9fec8..9e966490f1e57078ca4aee2b0b24fa73b672e70a 100644 (file)
@@ -20,6 +20,9 @@ class CompareCommand {
         case '--jenkins-xml':
           $parser = array('\Civi\CiUtil\JenkinsParser', 'parseXmlResults');
           break;
+        case '--csv':
+          $parser = array('\Civi\CiUtil\CSVParser', 'parseResults');
+          break;
         case '--out=txt':
           $printerType = 'txt';
           break;