EnvironmentCleanerService.php in SimpleTest 8.3
File
src/EnvironmentCleanerService.php
View source
<?php
namespace Drupal\simpletest;
use Drupal\Core\Database\Connection;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\File\FileSystem;
use Drupal\Core\Test\EnvironmentCleaner;
class EnvironmentCleanerService extends EnvironmentCleaner {
protected $messenger;
protected $translation;
protected $configFactory;
protected $cacheDefault;
public function __construct($root, Connection $test_database, Connection $results_database, MessengerInterface $messenger, TranslationInterface $translation, ConfigFactory $config, CacheBackendInterface $cache_default, FileSystem $file_system) {
$this->root = $root;
$this->testDatabase = $test_database;
$this->resultsDatabase = $results_database;
$this->messenger = $messenger;
$this->translation = $translation;
$this->configFactory = $config;
$this->cacheDefault = $cache_default;
$this->fileSystem = $file_system;
}
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');
}
}
public function cleanDatabase() {
$tables_removed = $this
->doCleanDatabase();
if ($tables_removed > 0) {
$this->messenger
->addMessage($this->translation
->formatPlural($tables_removed, 'Removed 1 leftover table.', 'Removed @count leftover tables.'));
}
else {
$this->messenger
->addMessage($this->translation
->translate('No leftover tables to remove.'));
}
}
public function cleanTemporaryDirectories() {
$directories_removed = $this
->doCleanTemporaryDirectories();
if ($directories_removed > 0) {
$this->messenger
->addMessage($this->translation
->formatPlural($directories_removed, 'Removed 1 temporary directory.', 'Removed @count temporary directories.'));
}
else {
$this->messenger
->addMessage($this->translation
->translate('No temporary directories to remove.'));
}
}
}