You are here

public function PHPUnit_Framework_TestCase::runBare in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/src/Framework/TestCase.php \PHPUnit_Framework_TestCase::runBare()

Runs the bare test sequence.

File

vendor/phpunit/phpunit/src/Framework/TestCase.php, line 720

Class

PHPUnit_Framework_TestCase
A TestCase defines the fixture to run multiple tests.

Code

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 (Throwable $_e) {
    $e = $_e;
  } catch (Exception $_e) {
    $e = $_e;
  }
  if (isset($_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 (Throwable $_e) {
    if (!isset($e)) {
      $e = $_e;
    }
  } 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 (Throwable $_e) {
      $e = $_e;
    } catch (Exception $_e) {
      $e = $_e;
    }
  }

  // Workaround for missing "finally".
  if (isset($e)) {
    if ($e instanceof PredictionException) {
      $e = new PHPUnit_Framework_AssertionFailedError($e
        ->getMessage());
    }
    if (!$e instanceof Exception) {

      // Rethrow Error directly on PHP 7 as onNotSuccessfulTest does not support it
      throw $e;
    }
    $this
      ->onNotSuccessfulTest($e);
  }
}