Changeset View
Changeset View
Standalone View
Standalone View
src/unit/engine/phutil/PhutilTestCase.php
| Show First 20 Lines • Show All 402 Lines • ▼ Show 20 Lines | /* -( Internals )---------------------------------------------------------- */ | ||||
| /** | /** | ||||
| * Mark the currently-running test as a failure. | * Mark the currently-running test as a failure. | ||||
| * | * | ||||
| * @param string Human-readable description of problems. | * @param string Human-readable description of problems. | ||||
| * @return void | * @return void | ||||
| * | * | ||||
| * @task internal | * @task internal | ||||
| */ | */ | ||||
| final private function failTest($reason) { | private function failTest($reason) { | ||||
| $this->resultTest(ArcanistUnitTestResult::RESULT_FAIL, $reason); | $this->resultTest(ArcanistUnitTestResult::RESULT_FAIL, $reason); | ||||
| } | } | ||||
| /** | /** | ||||
| * This was a triumph. I'm making a note here: HUGE SUCCESS. | * This was a triumph. I'm making a note here: HUGE SUCCESS. | ||||
| * | * | ||||
| * @param string Human-readable overstatement of satisfaction. | * @param string Human-readable overstatement of satisfaction. | ||||
| * @return void | * @return void | ||||
| * | * | ||||
| * @task internal | * @task internal | ||||
| */ | */ | ||||
| final private function passTest($reason) { | private function passTest($reason) { | ||||
| $this->resultTest(ArcanistUnitTestResult::RESULT_PASS, $reason); | $this->resultTest(ArcanistUnitTestResult::RESULT_PASS, $reason); | ||||
| } | } | ||||
| /** | /** | ||||
| * Mark the current running test as skipped. | * Mark the current running test as skipped. | ||||
| * | * | ||||
| * @param string Description for why this test was skipped. | * @param string Description for why this test was skipped. | ||||
| * @return void | * @return void | ||||
| * @task internal | * @task internal | ||||
| */ | */ | ||||
| final private function skipTest($reason) { | private function skipTest($reason) { | ||||
| $this->resultTest(ArcanistUnitTestResult::RESULT_SKIP, $reason); | $this->resultTest(ArcanistUnitTestResult::RESULT_SKIP, $reason); | ||||
| } | } | ||||
| final private function resultTest($test_result, $reason) { | private function resultTest($test_result, $reason) { | ||||
| $coverage = $this->endCoverage(); | $coverage = $this->endCoverage(); | ||||
| $result = new ArcanistUnitTestResult(); | $result = new ArcanistUnitTestResult(); | ||||
| $result->setCoverage($coverage); | $result->setCoverage($coverage); | ||||
| $result->setNamespace(get_class($this)); | $result->setNamespace(get_class($this)); | ||||
| $result->setName($this->runningTest); | $result->setName($this->runningTest); | ||||
| $result->setLink($this->getLink($this->runningTest)); | $result->setLink($this->getLink($this->runningTest)); | ||||
| $result->setResult($test_result); | $result->setResult($test_result); | ||||
| ▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | /* -( Internals )---------------------------------------------------------- */ | ||||
| final public function setEnableCoverage($enable_coverage) { | final public function setEnableCoverage($enable_coverage) { | ||||
| $this->enableCoverage = $enable_coverage; | $this->enableCoverage = $enable_coverage; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| /** | /** | ||||
| * @phutil-external-symbol function xdebug_start_code_coverage | * @phutil-external-symbol function xdebug_start_code_coverage | ||||
| */ | */ | ||||
| final private function beginCoverage() { | private function beginCoverage() { | ||||
| if (!$this->enableCoverage) { | if (!$this->enableCoverage) { | ||||
| return; | return; | ||||
| } | } | ||||
| $this->assertCoverageAvailable(); | $this->assertCoverageAvailable(); | ||||
| xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE); | xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE); | ||||
| } | } | ||||
| /** | /** | ||||
| * @phutil-external-symbol function xdebug_get_code_coverage | * @phutil-external-symbol function xdebug_get_code_coverage | ||||
| * @phutil-external-symbol function xdebug_stop_code_coverage | * @phutil-external-symbol function xdebug_stop_code_coverage | ||||
| */ | */ | ||||
| final private function endCoverage() { | private function endCoverage() { | ||||
| if (!$this->enableCoverage) { | if (!$this->enableCoverage) { | ||||
| return; | return; | ||||
| } | } | ||||
| $result = xdebug_get_code_coverage(); | $result = xdebug_get_code_coverage(); | ||||
| xdebug_stop_code_coverage($cleanup = false); | xdebug_stop_code_coverage($cleanup = false); | ||||
| $coverage = array(); | $coverage = array(); | ||||
| Show All 35 Lines | private function endCoverage() { | ||||
| // coverage data. | // coverage data. | ||||
| if ($this->paths) { | if ($this->paths) { | ||||
| $coverage = array_select_keys($coverage, $this->paths); | $coverage = array_select_keys($coverage, $this->paths); | ||||
| } | } | ||||
| return $coverage; | return $coverage; | ||||
| } | } | ||||
| final private function assertCoverageAvailable() { | private function assertCoverageAvailable() { | ||||
| if (!function_exists('xdebug_start_code_coverage')) { | if (!function_exists('xdebug_start_code_coverage')) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht("You've enabled code coverage but XDebug is not installed.")); | pht("You've enabled code coverage but XDebug is not installed.")); | ||||
| } | } | ||||
| } | } | ||||
| final public function getWorkingCopy() { | final public function getWorkingCopy() { | ||||
| return $this->workingCopy; | return $this->workingCopy; | ||||
| Show All 40 Lines | final public function setRenderer(ArcanistUnitRenderer $renderer) { | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| /** | /** | ||||
| * Returns info about the caller function. | * Returns info about the caller function. | ||||
| * | * | ||||
| * @return map | * @return map | ||||
| */ | */ | ||||
| final private static function getCallerInfo() { | private static function getCallerInfo() { | ||||
| $callee = array(); | $callee = array(); | ||||
| $caller = array(); | $caller = array(); | ||||
| $seen = false; | $seen = false; | ||||
| foreach (array_slice(debug_backtrace(), 1) as $location) { | foreach (array_slice(debug_backtrace(), 1) as $location) { | ||||
| $function = idx($location, 'function'); | $function = idx($location, 'function'); | ||||
| if (!$seen && preg_match('/^assert[A-Z]/', $function)) { | if (!$seen && preg_match('/^assert[A-Z]/', $function)) { | ||||
| ▲ Show 20 Lines • Show All 99 Lines • Show Last 20 Lines | |||||