protected function BrowserTestBase::getDefaultDriverInstance in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/BrowserTestBase.php \Drupal\Tests\BrowserTestBase::getDefaultDriverInstance()
- 9 core/tests/Drupal/Tests/BrowserTestBase.php \Drupal\Tests\BrowserTestBase::getDefaultDriverInstance()
Gets an instance of the default Mink driver.
Return value
Behat\Mink\Driver\DriverInterface Instance of default Mink driver.
Throws
\InvalidArgumentException When provided default Mink driver class can't be instantiated.
2 calls to BrowserTestBase::getDefaultDriverInstance()
- BrowserTestBase::initMink in core/
tests/ Drupal/ Tests/ BrowserTestBase.php - Initializes Mink sessions.
- BrowserTestBaseTest::testGetDefaultDriveInstance in core/
tests/ Drupal/ FunctionalTests/ BrowserTestBaseTest.php
File
- core/
tests/ Drupal/ Tests/ BrowserTestBase.php, line 304
Class
- BrowserTestBase
- Provides a test case for functional Drupal tests.
Namespace
Drupal\TestsCode
protected function getDefaultDriverInstance() {
// Get default driver params from environment if available.
if ($arg_json = $this
->getMinkDriverArgs()) {
$this->minkDefaultDriverArgs = json_decode($arg_json, TRUE);
}
// Get and check default driver class from environment if available.
if ($minkDriverClass = getenv('MINK_DRIVER_CLASS')) {
if (class_exists($minkDriverClass)) {
$this->minkDefaultDriverClass = $minkDriverClass;
}
else {
throw new \InvalidArgumentException("Can't instantiate provided {$minkDriverClass} class by environment as default driver class.");
}
}
if ($this->minkDefaultDriverClass === BrowserKitDriver::class) {
$driver = new $this->minkDefaultDriverClass(new DrupalTestBrowser());
}
elseif (is_array($this->minkDefaultDriverArgs)) {
// Use ReflectionClass to instantiate class with received params.
$reflector = new \ReflectionClass($this->minkDefaultDriverClass);
$driver = $reflector
->newInstanceArgs($this->minkDefaultDriverArgs);
}
else {
$driver = new $this->minkDefaultDriverClass();
}
return $driver;
}