You are here

public function EnvironmentCleanerService::cleanEnvironment in Drupal 8

Removes all test-related database tables and directories.

This method removes fixture files and database entries from the system under test.

Parameters

bool $clear_results: (optional) Whether to clear the test results database. Defaults to TRUE.

bool $clear_temp_directories: (optional) Whether to clear the test site directories. Defaults to TRUE.

bool $clear_database: (optional) Whether to clean up the fixture database. Defaults to TRUE.

Overrides EnvironmentCleaner::cleanEnvironment

File

core/modules/simpletest/src/EnvironmentCleanerService.php, line 74

Class

EnvironmentCleanerService
Uses containerized services to perform post-test cleanup.

Namespace

Drupal\simpletest

Code

public function cleanEnvironment($clear_results = TRUE, $clear_temp_directories = TRUE, $clear_database = TRUE) {
  $results_removed = 0;
  $clear_results = $this->configFactory
    ->get('simpletest.settings')
    ->get('clear_results');
  if ($clear_database) {
    $this
      ->cleanDatabase();
  }
  if ($clear_temp_directories) {
    $this
      ->cleanTemporaryDirectories();
  }
  if ($clear_results) {
    $results_removed = $this
      ->cleanResultsTable();
  }
  $this->cacheDefault
    ->delete('simpletest');
  $this->cacheDefault
    ->delete('simpletest_phpunit');
  if ($clear_results) {
    $this->messenger
      ->addMessage($this->translation
      ->formatPlural($results_removed, 'Removed 1 test result.', 'Removed @count test results.'));
  }
  else {
    $this->messenger
      ->addMessage($this->translation
      ->translate('Clear results is disabled and the test results table will not be cleared.'), 'warning');
  }
}