You are here

protected function TestSiteInstallCommand::prepareDatabasePrefix in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php \Drupal\TestSite\Commands\TestSiteInstallCommand::prepareDatabasePrefix()

Generates a database prefix for running tests.

The database prefix is used by prepareEnvironment() to setup a public files directory for the test to be run, which also contains the PHP error log, which is written to in case of a fatal error. Since that directory is based on the database prefix, all tests (even unit tests) need to have one, in order to access and read the error log.

The generated database table prefix is used for the Drupal installation being performed for the test. It is also used as user agent HTTP header it is also used in the user agent HTTP header value by BrowserTestBase, which is sent to the Drupal installation of the test. During early Drupal all bootstrap, the user agent HTTP header is parsed, and if it matches, database queries use the database table prefix that has been generated here.

Overrides TestSetupTrait::prepareDatabasePrefix

See also

\Drupal\Tests\BrowserTestBase::prepareEnvironment()

drupal_valid_test_ua()

File

core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php, line 262

Class

TestSiteInstallCommand
Command to create a test Drupal site.

Namespace

Drupal\TestSite\Commands

Code

protected function prepareDatabasePrefix() {

  // Override this method so that we can force a lock to be created.
  $test_db = new TestDatabase(NULL, TRUE);
  $this->siteDirectory = $test_db
    ->getTestSitePath();
  $this->databasePrefix = $test_db
    ->getDatabasePrefix();
}