phpunit-compare - Add support for reading results from CSV
[civicrm-core.git] / Civi / CiUtil / CSVParser.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