You are here

public function EnvironmentCleaner::cleanResultsTable in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Test/EnvironmentCleaner.php \Drupal\Core\Test\EnvironmentCleaner::cleanResultsTable()
  2. 9 core/lib/Drupal/Core/Test/EnvironmentCleaner.php \Drupal\Core\Test\EnvironmentCleaner::cleanResultsTable()

File

core/lib/Drupal/Core/Test/EnvironmentCleaner.php, line 171

Class

EnvironmentCleaner
Helper class for cleaning test environments.

Namespace

Drupal\Core\Test

Code

public function cleanResultsTable($test_id = NULL) {
  $count = 0;
  if ($test_id) {
    $count = $this->resultsDatabase
      ->query('SELECT COUNT([test_id]) FROM {simpletest_test_id} WHERE [test_id] = :test_id', [
      ':test_id' => $test_id,
    ])
      ->fetchField();
    $this->resultsDatabase
      ->delete('simpletest')
      ->condition('test_id', $test_id)
      ->execute();
    $this->resultsDatabase
      ->delete('simpletest_test_id')
      ->condition('test_id', $test_id)
      ->execute();
  }
  else {
    $count = $this->resultsDatabase
      ->query('SELECT COUNT([test_id]) FROM {simpletest_test_id}')
      ->fetchField();

    // Clear test results.
    $this->resultsDatabase
      ->delete('simpletest')
      ->execute();
    $this->resultsDatabase
      ->delete('simpletest_test_id')
      ->execute();
  }
  return $count;
}