function TestDatabase::__construct
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Test/TestDatabase.php \Drupal\Core\Test\TestDatabase::__construct()
- 10 core/lib/Drupal/Core/Test/TestDatabase.php \Drupal\Core\Test\TestDatabase::__construct()
- 11.x core/lib/Drupal/Core/Test/TestDatabase.php \Drupal\Core\Test\TestDatabase::__construct()
TestDatabase constructor.
Parameters
string|null $db_prefix: If not provided a new test lock is generated.
bool $create_lock: (optional) Whether or not to create a lock file. Defaults to FALSE. If the environment variable RUN_TESTS_CONCURRENCY is greater than 1 it will be overridden to TRUE regardless of its initial value.
Throws
\InvalidArgumentException Thrown when $db_prefix does not match the regular expression.
File
-
core/
lib/ Drupal/ Core/ Test/ TestDatabase.php, line 75
Class
- TestDatabase
- Provides helper methods for interacting with the fixture database.
Namespace
Drupal\Core\TestCode
public function __construct($db_prefix = NULL, $create_lock = FALSE) {
if ($db_prefix === NULL) {
$this->lockId = $this->getTestLock($create_lock);
$this->databasePrefix = 'test' . $this->lockId;
}
else {
$this->databasePrefix = $db_prefix;
// It is possible that we're running a test inside a test. In which case
// $db_prefix will be something like test12345678test90123456 and the
// generated lock ID for the running test method would be 90123456.
preg_match('/test(\\d+)$/', $db_prefix, $matches);
if (!isset($matches[1])) {
throw new \InvalidArgumentException("Invalid database prefix: {$db_prefix}");
}
$this->lockId = $matches[1];
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.