Commit | Line | Data |
---|---|---|
f03dc6b0 TO |
1 | <?php |
2 | namespace Civi\CiUtil; | |
3 | ||
4 | /** | |
5 | * Parse phpunit result files | |
6 | */ | |
7 | class 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 | |
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 | } | |
ef10e0b5 | 31 | } |