function TestSiteTearDownCommand::tearDown

Same name and namespace in other branches
  1. 9 core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php \Drupal\TestSite\Commands\TestSiteTearDownCommand::tearDown()
  2. 8.9.x core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php \Drupal\TestSite\Commands\TestSiteTearDownCommand::tearDown()
  3. 10 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()

1 call to TestSiteTearDownCommand::tearDown()
TestSiteTearDownCommand::execute in core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php

File

core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php, line 84

Class

TestSiteTearDownCommand
Command to tear down a test Drupal site.

Namespace

Drupal\TestSite\Commands

Code

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',
    ]);
}

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