function KernelTestBase::getTestDatabase

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::getTestDatabase()

Returns the test database for this test.

The returned object determines the database prefix and the test site directory.

Return value

\Drupal\Core\Test\TestDatabase The test database.

File

core/tests/Drupal/KernelTests/KernelTestBase.php, line 381

Class

KernelTestBase
Base class for functional integration tests.

Namespace

Drupal\KernelTests

Code

protected function getTestDatabase() : TestDatabase {
  if (!static::sharesEnvironment()) {
    return new TestDatabase();
  }
  $shared_database = getenv(self::SHARED_DATABASE_PREFIX_ENV);
  if ($shared_database === FALSE) {
    throw new \RuntimeException(sprintf('%s did not receive a shared database prefix from the test runner process. The prefix travels in the %s environment variable, which the forked test method process inherits.', static::class, self::SHARED_DATABASE_PREFIX_ENV));
  }
  [$prefix] = explode(':', $shared_database);
  return new TestDatabase($prefix);
}

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