Changeset View
Changeset View
Standalone View
Standalone View
src/unit/engine/PhutilUnitEngine.php
- This file was moved from src/unit/engine/PhutilUnitTestEngine.php.
| <?php | <?php | ||||
| /** | final class PhutilUnitEngine | ||||
| * Very basic unit test engine which runs libphutil tests. | extends ArcanistUnitEngine { | ||||
| */ | |||||
| final class PhutilUnitTestEngine extends ArcanistUnitTestEngine { | |||||
| public function getEngineConfigurationName() { | |||||
| return 'phutil'; | |||||
| } | |||||
| protected function supportsRunAllTests() { | const ENGINETYPE = 'phutil'; | ||||
| return true; | |||||
| } | |||||
| public function run() { | public function runTests() { | ||||
| if ($this->getRunAllTests()) { | |||||
| $run_tests = $this->getAllTests(); | $run_tests = $this->getAllTests(); | ||||
| } else { | |||||
| $run_tests = $this->getTestsForPaths(); | |||||
| } | |||||
| if (!$run_tests) { | |||||
| throw new ArcanistNoEffectException(pht('No tests to run.')); | |||||
| } | |||||
| $enable_coverage = $this->getEnableCoverage(); | |||||
| if ($enable_coverage !== false) { | |||||
| if (!function_exists('xdebug_start_code_coverage')) { | |||||
| if ($enable_coverage === true) { | |||||
| throw new ArcanistUsageException( | |||||
| pht( | |||||
| 'You specified %s but %s is not available, so '. | |||||
| 'coverage can not be enabled for %s.', | |||||
| '--coverage', | |||||
| 'XDebug', | |||||
| __CLASS__)); | |||||
| } | |||||
| } else { | |||||
| $enable_coverage = true; | |||||
| } | |||||
| } | |||||
| $test_cases = array(); | $test_cases = array(); | ||||
| foreach ($run_tests as $test_class) { | foreach ($run_tests as $test_class) { | ||||
| $test_case = newv($test_class, array()) | $test_case = newv($test_class, array()); | ||||
| ->setEnableCoverage($enable_coverage) | |||||
| ->setWorkingCopy($this->getWorkingCopy()); | |||||
| if ($this->getPaths()) { | |||||
| $test_case->setPaths($this->getPaths()); | |||||
| } | |||||
| if ($this->renderer) { | |||||
| $test_case->setRenderer($this->renderer); | |||||
| } | |||||
| $test_cases[] = $test_case; | $test_cases[] = $test_case; | ||||
| } | } | ||||
| foreach ($test_cases as $test_case) { | foreach ($test_cases as $test_case) { | ||||
| $test_case->willRunTestCases($test_cases); | $test_case->willRunTestCases($test_cases); | ||||
| } | } | ||||
| $results = array(); | $results = array(); | ||||
| foreach ($test_cases as $test_case) { | foreach ($test_cases as $test_case) { | ||||
| $results[] = $test_case->run(); | $result_list = $test_case->run(); | ||||
| $this->didRunTests($result_list); | |||||
| $results[] = $result_list; | |||||
| } | } | ||||
| $results = array_mergev($results); | $results = array_mergev($results); | ||||
| foreach ($test_cases as $test_case) { | foreach ($test_cases as $test_case) { | ||||
| $test_case->didRunTestCases($test_cases); | $test_case->didRunTestCases($test_cases); | ||||
| } | } | ||||
| return $results; | return $results; | ||||
| } | } | ||||
| private function getAllTests() { | private function getAllTests() { | ||||
| $project_root = $this->getWorkingCopy()->getProjectRoot(); | $project_root = $this->getPath(); | ||||
| $symbols = id(new PhutilSymbolLoader()) | $symbols = id(new PhutilSymbolLoader()) | ||||
| ->setType('class') | ->setType('class') | ||||
| ->setAncestorClass('PhutilTestCase') | ->setAncestorClass('PhutilTestCase') | ||||
| ->setConcreteOnly(true) | ->setConcreteOnly(true) | ||||
| ->selectSymbolsWithoutLoading(); | ->selectSymbolsWithoutLoading(); | ||||
| $in_working_copy = array(); | $in_working_copy = array(); | ||||
| ▲ Show 20 Lines • Show All 135 Lines • Show Last 20 Lines | |||||