Merge pull request #4999 from totten/master-autosave
[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
00be9182 11 public function __construct($phpunit = "phpunit", $envTestSuite = 'EnvTests') {
f03dc6b0
TO
12 $this->phpunit = $phpunit;
13 $this->envTestSuite = $envTestSuite;
14 }
15
16 /**
17 * @param array $tests
a6c01b45
CW
18 * @return array
19 * (string $testName => string $status)
f03dc6b0
TO
20 */
21 public function run($tests) {
22 $envTests = implode(' ', $tests);
23 $jsonFile = tempnam(sys_get_temp_dir(), 'phpunit-json-');
24 unlink($jsonFile);
25 $command = "env PHPUNIT_TESTS=\"$envTests\" {$this->phpunit} --log-json $jsonFile {$this->envTestSuite}";
26 echo "Running [$command]\n";
27 system($command);
28 $results = PHPUnitParser::parseJsonResults(file_get_contents($jsonFile));
29 unlink($jsonFile);
30 return $results;
31 }
96025800 32
ef10e0b5 33}