INFRA-125, CRM-15011 - Import phpunit-{antagonist,compare,indiv,ls} and jmat
[civicrm-core.git] / Civi / CiUtil / EnvTestRunner.php
diff --git a/Civi/CiUtil/EnvTestRunner.php b/Civi/CiUtil/EnvTestRunner.php
new file mode 100644 (file)
index 0000000..d16bd84
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+namespace Civi\CiUtil;
+
+/**
+ * Parse phpunit result files
+ */
+class EnvTestRunner {
+  protected $phpunit;
+  protected $envTestSuite;
+
+  function __construct($phpunit = "phpunit", $envTestSuite = 'EnvTests') {
+    $this->phpunit = $phpunit;
+    $this->envTestSuite = $envTestSuite;
+  }
+
+  /**
+   * @param array $tests
+   * @return array (string $testName => string $status)
+   */
+  public function run($tests) {
+    $envTests = implode(' ', $tests);
+    $jsonFile = tempnam(sys_get_temp_dir(), 'phpunit-json-');
+    unlink($jsonFile);
+    $command = "env PHPUNIT_TESTS=\"$envTests\" {$this->phpunit} --log-json $jsonFile {$this->envTestSuite}";
+    echo "Running [$command]\n";
+    system($command);
+    $results = PHPUnitParser::parseJsonResults(file_get_contents($jsonFile));
+    unlink($jsonFile);
+    return $results;
+  }
+}
\ No newline at end of file