You are here

public function DrupalTestCase::run in SimpleTest 6.2

Same name and namespace in other branches
  1. 5 drupal_test_case.php \DrupalTestCase::run()
  2. 6 drupal_test_case.php \DrupalTestCase::run()
  3. 7.2 drupal_web_test_case.php \DrupalTestCase::run()
  4. 7 drupal_web_test_case.php \DrupalTestCase::run()

Run all tests in this class.

Regardless of whether $methods are passed or not, only method names starting with "test" are executed.

Parameters

$methods: (optional) A list of method names in the test case class to run; e.g., array('testFoo', 'testBar'). By default, all methods of the class are taken into account, but it can be useful to only run a few selected test methods during debugging.

File

./drupal_web_test_case.php, line 453

Class

DrupalTestCase
Base class for Drupal tests.

Code

public function run(array $methods = array()) {

  // Initialize verbose debugging.
  simpletest_verbose(NULL, variable_get('file_directory_path', conf_path() . '/files'), get_class($this));

  // HTTP auth settings (<username>:<password>) for the simpletest browser
  // when sending requests to the test site.
  $this->httpauth_method = variable_get('simpletest_httpauth_method', CURLAUTH_BASIC);
  $username = variable_get('simpletest_httpauth_username', NULL);
  $password = variable_get('simpletest_httpauth_password', NULL);
  if ($username && $password) {
    $this->httpauth_credentials = $username . ':' . $password;
  }
  set_error_handler(array(
    $this,
    'errorHandler',
  ));
  $class = get_class($this);

  // Iterate through all the methods in this class, unless a specific list of
  // methods to run was passed.
  $class_methods = get_class_methods($class);
  if ($methods) {
    $class_methods = array_intersect($class_methods, $methods);
  }
  foreach ($class_methods as $method) {

    // If the current method starts with "test", run it - it's a test.
    if (strtolower(substr($method, 0, 4)) == 'test') {

      // Insert a fail record. This will be deleted on completion to ensure
      // that testing completed.
      $method_info = new ReflectionMethod($class, $method);
      $caller = array(
        'file' => $method_info
          ->getFileName(),
        'line' => $method_info
          ->getStartLine(),
        'function' => $class . '->' . $method . '()',
      );
      $completion_check_id = DrupalTestCase::insertAssert($this->testId, $class, FALSE, t('The test did not complete due to a fatal error.'), 'Completion check', $caller);
      $this
        ->setUp();
      try {
        $this
          ->{$method}();

        // Finish up.
      } catch (Exception $e) {
        $this
          ->exceptionHandler($e);
      }
      $this
        ->tearDown();

      // Remove the completion check record.
      DrupalTestCase::deleteAssert($completion_check_id);
    }
  }

  // Clear out the error messages and restore error handler.
  drupal_get_messages();
  restore_error_handler();
}