Changeset View
Changeset View
Standalone View
Standalone View
src/unit/engine/PhpunitResultParser.php
| <?php | <?php | ||||
| /** | /** | ||||
| * PHPUnit Result Parsing utility | * PHPUnit Result Parsing utility | ||||
| * | * | ||||
| * Intended to enable custom unit engines derived | * For an example on how to integrate with your test engine, see | ||||
| * from phpunit to reuse common business logic related | * @{class:PhpunitTestEngine}. | ||||
| * to parsing phpunit test results and reports | |||||
| * | |||||
| * For an example on how to integrate with your test | |||||
| * engine, see PhpunitTestEngine. | |||||
| * | |||||
| */ | */ | ||||
| final class PhpunitResultParser extends ArcanistBaseTestResultParser { | final class PhpunitResultParser extends ArcanistBaseTestResultParser { | ||||
| /** | /** | ||||
| * Parse test results from phpunit json report | * Parse test results from phpunit json report | ||||
| * | * | ||||
| * @param string $path Path to test | * @param string $path Path to test | ||||
| * @param string $test_results String containing phpunit json report | * @param string $test_results String containing phpunit json report | ||||
| * | * | ||||
| * @return array | * @return array | ||||
| */ | */ | ||||
| public function parseTestResults($path, $test_results) { | public function parseTestResults($path, $test_results) { | ||||
| if (!$test_results) { | if (!$test_results) { | ||||
| $result = id(new ArcanistUnitTestResult()) | $result = id(new ArcanistUnitTestResult()) | ||||
| ->setName($path) | ->setName($path) | ||||
| ->setUserData($this->stderr) | ->setUserData($this->stderr) | ||||
| ->setResult(ArcanistUnitTestResult::RESULT_BROKEN); | ->setResult(ArcanistUnitTestResult::RESULT_BROKEN); | ||||
| return array($result); | return array($result); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | private function readCoverage() { | ||||
| return $reports; | return $reports; | ||||
| } | } | ||||
| /** | /** | ||||
| * We need this non-sense to make json generated by phpunit | * We need this non-sense to make json generated by phpunit | ||||
| * valid. | * valid. | ||||
| * | * | ||||
| * @param string $json String containing JSON report | * @param string $json String containing JSON report | ||||
| * | |||||
| * @return array JSON decoded array | * @return array JSON decoded array | ||||
| */ | */ | ||||
| private function getJsonReport($json) { | private function getJsonReport($json) { | ||||
| if (empty($json)) { | if (empty($json)) { | ||||
| throw new Exception('JSON report file is empty, '. | throw new Exception('JSON report file is empty, '. | ||||
| 'it probably means that phpunit failed to run tests. '. | 'it probably means that phpunit failed to run tests. '. | ||||
| 'Try running arc unit with --trace option and then run '. | 'Try running arc unit with --trace option and then run '. | ||||
| 'generated phpunit command yourself, you might get the '. | 'generated phpunit command yourself, you might get the '. | ||||
| 'answer.' | 'answer.' | ||||
| ); | ); | ||||
| } | } | ||||
| $json = preg_replace('/}{\s*"/', '},{"', $json); | $json = preg_replace('/}{\s*"/', '},{"', $json); | ||||
| $json = '['.$json.']'; | $json = '['.$json.']'; | ||||
| $json = json_decode($json); | $json = json_decode($json); | ||||
| if (!is_array($json)) { | if (!is_array($json)) { | ||||
| throw new Exception('JSON could not be decoded'); | throw new Exception('JSON could not be decoded'); | ||||
| } | } | ||||
| return $json; | return $json; | ||||
| } | } | ||||
| } | } | ||||