function EnvironmentCleaner::cleanResultsTable

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Test/EnvironmentCleaner.php \Drupal\Core\Test\EnvironmentCleaner::cleanResultsTable()

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.