本文整理汇总了PHP中PHPUnit_Util_GlobalState::backupGlobals方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Util_GlobalState::backupGlobals方法的具体用法?PHP PHPUnit_Util_GlobalState::backupGlobals怎么用?PHP PHPUnit_Util_GlobalState::backupGlobals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Util_GlobalState
的用法示例。
在下文中一共展示了PHPUnit_Util_GlobalState::backupGlobals方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
try {
if ($this->inIsolation) {
$this->setUpBeforeClass();
}
$this->setExpectedExceptionFromAnnotation();
$this->setUp();
$this->checkRequirements();
$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 {
$this->tearDown();
if ($this->inIsolation) {
$this->tearDownAfterClass();
}
} 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) {
setlocale($category, $locale);
}
// Perform assertion on output.
if (!isset($e)) {
try {
if ($this->outputExpectedRegex !== NULL) {
$this->hasPerformedExpectationsOnOutput = TRUE;
$this->assertRegExp($this->outputExpectedRegex, $this->output);
$this->outputExpectedRegex = NULL;
//.........这里部分代码省略.........
示例2: 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 (version_compare(PHP_VERSION, '5.3', '>') && $this->backupStaticAttributes === TRUE) {
PHPUnit_Util_GlobalState::backupStaticAttributes($this->backupStaticAttributesBlacklist);
}
}
// Start output buffering.
if ($this->useOutputBuffering === TRUE) {
ob_start();
}
// Clean up stat cache.
clearstatcache();
// Run the test.
try {
// Set up the fixture.
if ($this->inIsolation) {
$this->setUpBeforeClass();
}
$this->setUp();
// Assert pre-conditions.
$this->assertPreConditions();
$this->testResult = $this->runTest();
// Assert post-conditions.
$this->assertPostConditions();
// Verify Mock Object conditions.
foreach ($this->mockObjects as $mockObject) {
$this->numAssertions++;
$mockObject->__phpunit_verify();
$mockObject->__phpunit_cleanup();
}
$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();
}
$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 {
$this->tearDown();
if ($this->inIsolation) {
$this->tearDownAfterClass();
}
} catch (Exception $_e) {
if (!isset($e)) {
$e = $_e;
}
}
// Stop output buffering.
if ($this->useOutputBuffering === TRUE) {
ob_end_clean();
}
// Clean up stat cache.
clearstatcache();
// 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 (version_compare(PHP_VERSION, '5.3', '>') && $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) {
setlocale($category, $locale);
}
// Workaround for missing "finally".
if (isset($e)) {
$this->onNotSuccessfulTest($e);
}
}
示例3: 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);
}
}
$this->startOutputBuffering();
// Clean up stat cache.
clearstatcache();
// Backup the cwd
$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 (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 {
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;
}
}
// 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.
//.........这里部分代码省略.........