You are here

public function PHPUnit_Framework_TestSuite::run in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/src/Framework/TestSuite.php \PHPUnit_Framework_TestSuite::run()

Runs the tests and collects their result in a TestResult.

Parameters

PHPUnit_Framework_TestResult $result:

Return value

PHPUnit_Framework_TestResult

Overrides PHPUnit_Framework_Test::run

File

vendor/phpunit/phpunit/src/Framework/TestSuite.php, line 660

Class

PHPUnit_Framework_TestSuite
A TestSuite is a composite of Tests. It runs a collection of test cases.

Code

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(array(
          $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
        ->setDisallowChangesToGlobalState($this->disallowChangesToGlobalState);
      $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;
}