function simpletest_drush_run_test

6.x test.drush.inc simpletest_drush_run_test($class)
4.x test.drush.inc simpletest_drush_run_test($class)
5.x test.drush.inc simpletest_drush_run_test($class)

Run a single test and display any failure messages.

1 call to simpletest_drush_run_test()
drush_test_run in commands/core/test.drush.inc
Test-run command callback.

File

commands/core/test.drush.inc, line 160
Simpletest module drush integration.

Code

function simpletest_drush_run_test($class) {
  drush_log(dt('Starting test @test.', array('@test' => $class)), 'ok');
  if (drush_drupal_major_version() >= 7) {
    $test_id = db_insert('simpletest_test_id')->useDefaults(array('test_id'))->execute();
  }
  else {
    db_query('INSERT INTO {simpletest_test_id} (test_id) VALUES (default)');
    $test_id = db_last_insert_id('simpletest_test_id', 'test_id');
  }
  $test = new $class($test_id);

  if ($methods_string = drush_get_option('methods')) {
    foreach (explode(',', $methods_string) as $method) {
      $methods[] = trim($method);
    }
    $test->run($methods);
  }
  else {
    $test->run();
  }

  $info = $test->getInfo();
  $status = ((isset($test->results['#fail']) && $test->results['#fail'] > 0) || (isset($test->results['#exception']) && $test->results['#exception'] > 0) ? 'error' : 'ok');
  drush_log($info['name'] . ' ' . _simpletest_format_summary_line($test->results), $status);

  if ($dir = drush_get_option('xml')) {
    drush_test_xml_results($test_id, $dir, $info);
  }
  if ($status === 'error') {
    if (drush_drupal_major_version() >= 7) {
      $args = array(':test_id' => $test_id);
      $result = db_query("SELECT * FROM {simpletest} WHERE test_id = :test_id AND status IN ('exception', 'fail') ORDER BY test_class, message_id", $args);
      foreach ($result as $record) {
        drush_set_error('DRUSH_TEST_FAIL', dt("Test !function failed: !message in !file on line !line", array(
          '!function' => $record->function,
          '!message' => $record->message,
          '!file' => $record->file,
          '!line' => $record->line,
        )));
      }
    }
    else {
      $result = db_query("SELECT * FROM {simpletest} WHERE test_id = %d AND status IN ('exception', 'fail') ORDER BY test_class, message_id", $test_id);
      while ($row = db_fetch_object($result)) {
        drush_set_error('DRUSH_TEST_FAIL', dt("Test !function failed: !message in !file on line !line", array(
          '!function' => $row->function,
          '!message' => $row->message,
          '!file' => $row->file,
          '!line' => $row->line,
        )));
      }
    }
  }
}