You are here

public function EnvironmentCleaner::cleanResultsTable in Drupal 9

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

Clears test result tables from the results database.

Parameters

$test_id: Test ID to remove results for, or NULL to remove all results.

Return value

int The number of results that were removed.

Overrides EnvironmentCleanerInterface::cleanResultsTable

1 call to EnvironmentCleaner::cleanResultsTable()
EnvironmentCleaner::cleanEnvironment in core/lib/Drupal/Core/Test/EnvironmentCleaner.php
Removes all test-related database tables and directories.

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;
}