/** * 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; } else { if ($this->outputExpectedString !== NULL) { $this->hasPerformedExpectationsOnOutput = TRUE; $this->assertEquals($this->outputExpectedString, $this->output); $this->outputExpectedString = NULL; } } } catch (Exception $_e) { $e = $_e; } } // Workaround for missing "finally". if (isset($e)) { $this->onNotSuccessfulTest($e); } }
/** * 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); } }
/** * 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. 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". if (isset($e)) { $this->onNotSuccessfulTest($e); } }