public function PHPUnit_Framework_TestSuite::run

Runs the tests and collects their result in a TestResult.

Parameters

PHPUnit_Framework_TestResult $result:

mixed $filter:

array $groups:

array $excludeGroups:

boolean $processIsolation:

Return value

PHPUnit_Framework_TestResult

Throws

PHPUnit_Framework_Exception

Overrides PHPUnit_Framework_Test::run

File

drupal/core/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php, line 627

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, $filter = FALSE, array $groups = array(), array $excludeGroups = array(), $processIsolation = FALSE) {
  if ($result === NULL) {
    $result = $this
      ->createResult();
  }
  $result
    ->startTestSuite($this);
  $doSetup = TRUE;
  if (!empty($excludeGroups)) {
    foreach ($this->groups as $_group => $_tests) {
      if (in_array($_group, $excludeGroups) && count($_tests) == count($this->tests)) {
        $doSetup = FALSE;
      }
    }
  }
  if ($doSetup) {
    try {
      $this
        ->setUp();
      if ($this->testCase && class_exists($this->name, false) && method_exists($this->name, 'setUpBeforeClass')) {
        call_user_func(array(
          $this->name,
          'setUpBeforeClass',
        ));
      }
    } 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;
    }
  }
  if (empty($groups)) {
    $tests = $this->tests;
  }
  else {
    $tests = new SplObjectStorage();
    foreach ($groups as $group) {
      if (isset($this->groups[$group])) {
        foreach ($this->groups[$group] as $test) {
          $tests
            ->attach($test);
        }
      }
    }
  }
  foreach ($tests as $test) {
    if ($result
      ->shouldStop()) {
      break;
    }
    if ($test instanceof PHPUnit_Framework_TestSuite) {
      $test
        ->setBackupGlobals($this->backupGlobals);
      $test
        ->setBackupStaticAttributes($this->backupStaticAttributes);
      $test
        ->run($result, $filter, $groups, $excludeGroups, $processIsolation);
    }
    else {
      $runTest = TRUE;
      if ($filter !== FALSE) {
        $tmp = PHPUnit_Util_Test::describe($test, FALSE);
        if ($tmp[0] != '') {
          $name = join('::', $tmp);
        }
        else {
          $name = $tmp[1];
        }
        if (preg_match($filter, $name) == 0) {
          $runTest = FALSE;
        }
      }
      if ($runTest && !empty($excludeGroups)) {
        foreach ($this->groups as $_group => $_tests) {
          if (in_array($_group, $excludeGroups)) {
            foreach ($_tests as $_test) {
              if ($test === $_test) {
                $runTest = FALSE;
                break 2;
              }
            }
          }
        }
      }
      if ($runTest) {
        if ($test instanceof PHPUnit_Framework_TestCase) {
          $test
            ->setBackupGlobals($this->backupGlobals);
          $test
            ->setBackupStaticAttributes($this->backupStaticAttributes);
          $test
            ->setRunTestInSeparateProcess($processIsolation);
        }
        $this
          ->runTest($test, $result);
      }
    }
  }
  if ($doSetup) {
    if ($this->testCase && class_exists($this->name, false) && method_exists($this->name, 'tearDownAfterClass')) {
      call_user_func(array(
        $this->name,
        'tearDownAfterClass',
      ));
    }
    $this
      ->tearDown();
  }
  $result
    ->endTestSuite($this);
  return $result;
}