You are here

protected function TestSiteTearDownCommand::tearDown in Drupal 8

Same name and namespace in other branches
  1. 9 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
Executes the current command.

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) {

  // Connect to the test database.
  $root = dirname(dirname(dirname(dirname(dirname(__DIR__)))));
  $database = Database::convertDbUrlToConnectionInfo($db_url, $root);
  $database['prefix'] = [
    'default' => $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',
  ]);
}