INFRA-125, CRM-15011 - Import phpunit-{antagonist,compare,indiv,ls} and jmat
[civicrm-core.git] / Civi / CiUtil / EnvTestRunner.php
CommitLineData
f03dc6b0
TO
1<?php
2namespace Civi\CiUtil;
3
4/**
5 * Parse phpunit result files
6 */
7class EnvTestRunner {
8 protected $phpunit;
9 protected $envTestSuite;
10
11 function __construct($phpunit = "phpunit", $envTestSuite = 'EnvTests') {
12 $this->phpunit = $phpunit;
13 $this->envTestSuite = $envTestSuite;
14 }
15
16 /**
17 * @param array $tests
18 * @return array (string $testName => string $status)
19 */
20 public function run($tests) {
21 $envTests = implode(' ', $tests);
22 $jsonFile = tempnam(sys_get_temp_dir(), 'phpunit-json-');
23 unlink($jsonFile);
24 $command = "env PHPUNIT_TESTS=\"$envTests\" {$this->phpunit} --log-json $jsonFile {$this->envTestSuite}";
25 echo "Running [$command]\n";
26 system($command);
27 $results = PHPUnitParser::parseJsonResults(file_get_contents($jsonFile));
28 unlink($jsonFile);
29 return $results;
30 }
31}