function KernelTestBase::allocateSharedDatabase
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::allocateSharedDatabase()
Allocates one database prefix for the whole test class.
Attributes
#[BeforeClass]
File
-
core/
tests/ Drupal/ KernelTests/ KernelTestBase.php, line 301
Class
- KernelTestBase
- Base class for functional integration tests.
Namespace
Drupal\KernelTestsCode
public static function allocateSharedDatabase() : void {
if (!static::sharesEnvironment()) {
return;
}
// PHPUnit runs this once in the test runner process, before it forks the
// first test method, and once again inside every forked process. The runner
// process allocates the prefix and exports it; the forked processes inherit
// the environment and read it back.
if (getenv(self::SHARED_DATABASE_PREFIX_ENV) !== FALSE) {
// A forked test method process: the prefix is already allocated.
return;
}
// Force a lock. This prefix stays in use for as long as the whole test
// class runs, so it has to be reserved against concurrent test runners.
$test_database = new TestDatabase(NULL, create_lock: TRUE);
putenv(self::SHARED_DATABASE_PREFIX_ENV . '=' . $test_database->getDatabasePrefix() . ':' . getmypid());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.