You are here

protected function TestSiteTearDownCommand::tearDown in Drupal 9

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

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