doCleanDatabase(); } if ($clear_temp_directories) { $this->doCleanTemporaryDirectories(); } if ($clear_results) { $count = $this->cleanResults(); $this->output->write('Test results removed: ' . $count); } else { $this->output->write('Test results were not removed.'); } } /** * {@inheritdoc} */ public function cleanDatabase(): void { $count = $this->doCleanDatabase(); if ($count > 0) { $this->output->write('Leftover tables removed: ' . $count); } else { $this->output->write('No leftover tables to remove.'); } } /** * Performs the fixture database cleanup. * * @return int * The number of tables that were removed. */ protected function doCleanDatabase(): int { /** @var \Drupal\Core\Database\Schema $schema */ $schema = $this->testDatabase->schema(); $tables = $schema->findTables('test%'); $count = 0; foreach ($tables as $table) { // Only drop tables which begin wih 'test' followed by digits, for // example, {test12345678node__body}. if (preg_match('/^test\d+.*/', $table, $matches)) { $schema->dropTable($matches[0]); $count++; } } return $count; } /** * {@inheritdoc} */ public function cleanTemporaryDirectories(): void { $count = $this->doCleanTemporaryDirectories(); if ($count > 0) { $this->output->write('Temporary directories removed: ' . $count); } else { $this->output->write('No temporary directories to remove.'); } } /** * Performs the cleanup of temporary test directories. * * @return int * The count of temporary directories removed. */ protected function doCleanTemporaryDirectories(): int { $count = 0; $simpletest_dir = $this->root . '/sites/simpletest'; if (is_dir($simpletest_dir)) { $files = scandir($simpletest_dir); foreach ($files as $file) { if ($file[0] != '.') { $path = $simpletest_dir . '/' . $file; $this->fileSystem->deleteRecursive($path, function ($any_path) { @chmod($any_path, 0700); }); $count++; } } } return $count; } /** * {@inheritdoc} */ public function cleanResults(?TestRun $test_run = NULL): int { return $test_run ? $test_run->removeResults() : $this->testRunResultsStorage->cleanUp(); } }