<?php
/**
* A custom unit test engine for Arcanist.
*
* This unit test engine provides a mechanism for combining multiple Arcanist
* unit test engines into a single "proxy" engine. This give us a much greater
* level of control over the behavior of `arc unit` until
* [[https://secure.phabricator.com/T5568 | T5568: Support `.arcunit`, similar
* to `.arclint`]] is resolved upstream.
*/
final class CustomTestEngine extends ArcanistUnitTestEngine {
protected function supportsRunAllTests() {
return true;
}
public function run() {
$paths = $this->getPaths();
// If we are running with `--everything` then `$paths` will be `null`.
if (!$paths) {
$paths = array();
}
$engines = array();
$results = array();
$exceptions = array();
$engines[] = $this->getPhpunitEngine(preg_grep('(some_regex)', $paths));
$engines[] = $this->getPhutilEngine(preg_grep('(some_regex)', $paths));
foreach ($engines as $engine) {
$engine
->setWorkingCopy($this->getWorkingCopy())
->setEnableAsyncTests($this->getEnableAsyncTests())
->setEnableCoverage($this->getEnableCoverage());
if ($engine->supportsRunAllTests()) {
$engine->setRunAllTests($this->getRunAllTests());
}
try {
$results[] = $engine->run();
} catch (ArcanistNoEffectException $ex) {
$exceptions[] = $ex;
}
}
if (!$results) {
// If all engines throw an `ArcanistNoEffectException`, then we should
// preserve this behavior.
throw new ArcanistNoEffectException(pht('No tests to run.'));
}
return array_mergev($results);
}
private function getPhpunitEngine(array $paths) {
return id(new CustomPhpunitTestEngine())
->setConfigurationManager($configuration_manager)
->setPaths($paths);
}
private function getPhutilEngine(array $paths) {
return id(new PhutilUnitTestEngine())
->setConfigurationManager($this->getConfigurationManager())
->setPaths($paths);
}
}