本文整理汇总了PHP中PHPUnit_Util_Test::getHookMethods方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Util_Test::getHookMethods方法的具体用法?PHP PHPUnit_Util_Test::getHookMethods怎么用?PHP PHPUnit_Util_Test::getHookMethods使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Util_Test
的用法示例。
在下文中一共展示了PHPUnit_Util_Test::getHookMethods方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeClass
public function beforeClass(SuiteEvent $e)
{
foreach ($e->getSuite()->tests() as $test) {
/** @var $test \PHPUnit_Framework_Test * */
$testClass = get_class($test);
$this->hooks[$testClass] = \PHPUnit_Util_Test::getHookMethods($testClass);
}
$this->runHooks('beforeClass');
}
示例2: beforeClass
public function beforeClass(SuiteEvent $e)
{
foreach ($e->getSuite()->tests() as $test) {
/** @var $test \PHPUnit_Framework_Test * */
if ($test instanceof \PHPUnit_Framework_TestSuite_DataProvider) {
$potentialTestClass = strstr($test->getName(), '::', true);
$this->hooks[$potentialTestClass] = \PHPUnit_Util_Test::getHookMethods($potentialTestClass);
}
$testClass = get_class($test);
$this->hooks[$testClass] = \PHPUnit_Util_Test::getHookMethods($testClass);
}
$this->runHooks('beforeClass');
}
示例3: runBare
/**
* Runs the bare test sequence.
*/
public function runBare()
{
$this->numAssertions = 0;
$this->snapshotGlobalState();
$this->startOutputBuffering();
clearstatcache();
$currentWorkingDirectory = getcwd();
$hookMethods = PHPUnit_Util_Test::getHookMethods(get_class($this));
try {
$hasMetRequirements = false;
$this->checkRequirements();
$hasMetRequirements = true;
if ($this->inIsolation) {
foreach ($hookMethods['beforeClass'] as $method) {
$this->{$method}();
}
}
$this->setExpectedExceptionFromAnnotation();
foreach ($hookMethods['before'] as $method) {
$this->{$method}();
}
$this->assertPreConditions();
$this->testResult = $this->runTest();
$this->verifyMockObjects();
$this->assertPostConditions();
$this->status = PHPUnit_Runner_BaseTestRunner::STATUS_PASSED;
} catch (PHPUnit_Framework_IncompleteTest $e) {
$this->status = PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE;
$this->statusMessage = $e->getMessage();
} catch (PHPUnit_Framework_SkippedTest $e) {
$this->status = PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED;
$this->statusMessage = $e->getMessage();
} catch (PHPUnit_Framework_AssertionFailedError $e) {
$this->status = PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE;
$this->statusMessage = $e->getMessage();
} catch (PredictionException $e) {
$this->status = PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE;
$this->statusMessage = $e->getMessage();
} catch (Exception $e) {
$this->status = PHPUnit_Runner_BaseTestRunner::STATUS_ERROR;
$this->statusMessage = $e->getMessage();
}
// Clean up the mock objects.
$this->mockObjects = array();
$this->prophet = null;
// Tear down the fixture. An exception raised in tearDown() will be
// caught and passed on when no exception was raised before.
try {
if ($hasMetRequirements) {
foreach ($hookMethods['after'] as $method) {
$this->{$method}();
}
if ($this->inIsolation) {
foreach ($hookMethods['afterClass'] as $method) {
$this->{$method}();
}
}
}
} catch (Exception $_e) {
if (!isset($e)) {
$e = $_e;
}
}
try {
$this->stopOutputBuffering();
} catch (PHPUnit_Framework_RiskyTestError $_e) {
if (!isset($e)) {
$e = $_e;
}
}
clearstatcache();
if ($currentWorkingDirectory != getcwd()) {
chdir($currentWorkingDirectory);
}
$this->restoreGlobalState();
// Clean up INI settings.
foreach ($this->iniSettings as $varName => $oldValue) {
ini_set($varName, $oldValue);
}
$this->iniSettings = array();
// Clean up locale settings.
foreach ($this->locale as $category => $locale) {
setlocale($category, $locale);
}
// Perform assertion on output.
if (!isset($e)) {
try {
if ($this->outputExpectedRegex !== null) {
$this->assertRegExp($this->outputExpectedRegex, $this->output);
} elseif ($this->outputExpectedString !== null) {
$this->assertEquals($this->outputExpectedString, $this->output);
}
} catch (Exception $_e) {
$e = $_e;
}
}
// Workaround for missing "finally".
//.........这里部分代码省略.........
示例4: run
/**
* Runs the tests and collects their result in a TestResult.
*
* @param PHPUnit_Framework_TestResult $result
* @return PHPUnit_Framework_TestResult
*/
public function run(PHPUnit_Framework_TestResult $result = null)
{
if ($result === null) {
$result = $this->createResult();
}
if (count($this) == 0) {
return $result;
}
$hookMethods = PHPUnit_Util_Test::getHookMethods($this->name);
$result->startTestSuite($this);
try {
$this->setUp();
foreach ($hookMethods['beforeClass'] as $beforeClassMethod) {
if ($this->testCase === true && class_exists($this->name, false) && method_exists($this->name, $beforeClassMethod)) {
if ($missingRequirements = PHPUnit_Util_Test::getMissingRequirements($this->name, $beforeClassMethod)) {
$this->markTestSuiteSkipped(implode(PHP_EOL, $missingRequirements));
}
call_user_func([$this->name, $beforeClassMethod]);
}
}
} catch (PHPUnit_Framework_SkippedTestSuiteError $e) {
$numTests = count($this);
for ($i = 0; $i < $numTests; $i++) {
$result->startTest($this);
$result->addFailure($this, $e, 0);
$result->endTest($this, 0);
}
$this->tearDown();
$result->endTestSuite($this);
return $result;
} catch (Throwable $_t) {
$t = $_t;
} catch (Exception $_t) {
$t = $_t;
}
if (isset($t)) {
$numTests = count($this);
for ($i = 0; $i < $numTests; $i++) {
$result->startTest($this);
$result->addError($this, $t, 0);
$result->endTest($this, 0);
}
$this->tearDown();
$result->endTestSuite($this);
return $result;
}
foreach ($this as $test) {
if ($result->shouldStop()) {
break;
}
if ($test instanceof PHPUnit_Framework_TestCase || $test instanceof self) {
$test->setbeStrictAboutChangesToGlobalState($this->beStrictAboutChangesToGlobalState);
$test->setBackupGlobals($this->backupGlobals);
$test->setBackupStaticAttributes($this->backupStaticAttributes);
$test->setRunTestInSeparateProcess($this->runTestInSeparateProcess);
}
$test->run($result);
}
foreach ($hookMethods['afterClass'] as $afterClassMethod) {
if ($this->testCase === true && class_exists($this->name, false) && method_exists($this->name, $afterClassMethod)) {
call_user_func([$this->name, $afterClassMethod]);
}
}
$this->tearDown();
$result->endTestSuite($this);
return $result;
}
示例5: runBare
/**
* Runs the bare test sequence.
*/
public function runBare()
{
$this->numAssertions = 0;
// Backup the $GLOBALS array and static attributes.
if ($this->runTestInSeparateProcess !== true && $this->inIsolation !== true) {
if ($this->backupGlobals === null || $this->backupGlobals === true) {
PHPUnit_Util_GlobalState::backupGlobals($this->backupGlobalsBlacklist);
}
if ($this->backupStaticAttributes === true) {
PHPUnit_Util_GlobalState::backupStaticAttributes($this->backupStaticAttributesBlacklist);
}
}
// Start output buffering.
ob_start();
$this->outputBufferingActive = true;
// Clean up stat cache.
clearstatcache();
// Backup the cwd
$currentWorkingDirectory = getcwd();
$hookMethods = PHPUnit_Util_Test::getHookMethods(get_class($this));
try {
$this->checkRequirements();
if ($this->inIsolation) {
foreach ($hookMethods['beforeClass'] as $method) {
$this->{$method}();
}
}
$this->setExpectedExceptionFromAnnotation();
foreach ($hookMethods['before'] as $method) {
$this->{$method}();
}
$this->assertPreConditions();
$this->testResult = $this->runTest();
$this->verifyMockObjects();
$this->assertPostConditions();
$this->status = PHPUnit_Runner_BaseTestRunner::STATUS_PASSED;
} catch (PHPUnit_Framework_IncompleteTest $e) {
$this->status = PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE;
$this->statusMessage = $e->getMessage();
} catch (PHPUnit_Framework_SkippedTest $e) {
$this->status = PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED;
$this->statusMessage = $e->getMessage();
} catch (PHPUnit_Framework_AssertionFailedError $e) {
$this->status = PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE;
$this->statusMessage = $e->getMessage();
} catch (Exception $e) {
$this->status = PHPUnit_Runner_BaseTestRunner::STATUS_ERROR;
$this->statusMessage = $e->getMessage();
}
// Clean up the mock objects.
$this->mockObjects = array();
// Tear down the fixture. An exception raised in tearDown() will be
// caught and passed on when no exception was raised before.
try {
foreach ($hookMethods['after'] as $method) {
$this->{$method}();
}
if ($this->inIsolation) {
foreach ($hookMethods['afterClass'] as $method) {
$this->{$method}();
}
}
} catch (Exception $_e) {
if (!isset($e)) {
$e = $_e;
}
}
// Stop output buffering.
if ($this->outputCallback === false) {
$this->output = ob_get_contents();
} else {
$this->output = call_user_func_array($this->outputCallback, array(ob_get_contents()));
}
ob_end_clean();
$this->outputBufferingActive = false;
// Clean up stat cache.
clearstatcache();
// Restore the cwd if it was changed by the test
if ($currentWorkingDirectory != getcwd()) {
chdir($currentWorkingDirectory);
}
// Restore the $GLOBALS array and static attributes.
if ($this->runTestInSeparateProcess !== true && $this->inIsolation !== true) {
if ($this->backupGlobals === null || $this->backupGlobals === true) {
PHPUnit_Util_GlobalState::restoreGlobals($this->backupGlobalsBlacklist);
}
if ($this->backupStaticAttributes === true) {
PHPUnit_Util_GlobalState::restoreStaticAttributes();
}
}
// Clean up INI settings.
foreach ($this->iniSettings as $varName => $oldValue) {
ini_set($varName, $oldValue);
}
$this->iniSettings = array();
// Clean up locale settings.
foreach ($this->locale as $category => $locale) {
//.........这里部分代码省略.........
示例6: run
/**
* Runs the tests and collects their result in a TestResult.
*
* @param PHPUnit_Framework_TestResult $result
* @return PHPUnit_Framework_TestResult
*/
public function run(PHPUnit_Framework_TestResult $result = null)
{
if ($result === null) {
$result = $this->createResult();
}
if (count($this) == 0) {
return $result;
}
$hookMethods = PHPUnit_Util_Test::getHookMethods($this->name);
$result->startTestSuite($this);
try {
$this->setUp();
foreach ($hookMethods['beforeClass'] as $beforeClassMethod) {
if ($this->testCase === true && class_exists($this->name, false) && method_exists($this->name, $beforeClassMethod)) {
call_user_func(array($this->name, $beforeClassMethod));
}
}
} catch (PHPUnit_Framework_SkippedTestSuiteError $e) {
$numTests = count($this);
for ($i = 0; $i < $numTests; $i++) {
$result->addFailure($this, $e, 0);
}
return $result;
} catch (Exception $e) {
$numTests = count($this);
for ($i = 0; $i < $numTests; $i++) {
$result->addError($this, $e, 0);
}
return $result;
}
foreach ($this as $test) {
if ($result->shouldStop()) {
break;
}
if ($test instanceof PHPUnit_Framework_TestCase || $test instanceof PHPUnit_Framework_TestSuite) {
$test->setBackupGlobals($this->backupGlobals);
$test->setBackupStaticAttributes($this->backupStaticAttributes);
$test->setRunTestInSeparateProcess($this->runTestInSeparateProcess);
}
$test->run($result);
}
foreach ($hookMethods['afterClass'] as $afterClassMethod) {
if ($this->testCase === true && class_exists($this->name, false) && method_exists($this->name, $afterClassMethod)) {
call_user_func(array($this->name, $afterClassMethod));
}
}
$this->tearDown();
$result->endTestSuite($this);
return $result;
}