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