protected function TestSiteTearDownCommand::tearDown in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php \Drupal\TestSite\Commands\TestSiteTearDownCommand::tearDown()
- 9 core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php \Drupal\TestSite\Commands\TestSiteTearDownCommand::tearDown()
Removes a given instance by deleting all the database tables and files.
Parameters
\Drupal\Core\Test\TestDatabase $test_database: The test database object.
string $db_url: The database URL.
See also
\Drupal\Tests\BrowserTestBase::cleanupEnvironment()
File
- core/
tests/ Drupal/ TestSite/ Commands/ TestSiteTearDownCommand.php, line 80
Class
- TestSiteTearDownCommand
- Command to tear down a test Drupal site.
Namespace
Drupal\TestSite\CommandsCode
protected function tearDown(TestDatabase $test_database, $db_url) : void {
// Connect to the test database.
$root = dirname(__DIR__, 5);
$database = Database::convertDbUrlToConnectionInfo($db_url, $root);
$database['prefix'] = $test_database
->getDatabasePrefix();
Database::addConnectionInfo(__CLASS__, 'default', $database);
// Remove all the tables.
$schema = Database::getConnection('default', __CLASS__)
->schema();
$tables = $schema
->findTables('%');
array_walk($tables, [
$schema,
'dropTable',
]);
// Delete test site directory.
$this
->fileUnmanagedDeleteRecursive($root . DIRECTORY_SEPARATOR . $test_database
->getTestSitePath(), [
BrowserTestBase::class,
'filePreDeleteCallback',
]);
}