function BrowserTestBase::getDefaultDriverInstance

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/BrowserTestBase.php \Drupal\Tests\BrowserTestBase::getDefaultDriverInstance()
  2. 10 core/tests/Drupal/Tests/BrowserTestBase.php \Drupal\Tests\BrowserTestBase::getDefaultDriverInstance()
  3. 11.x 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.

3 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
QuickEditLoadingTest::testConcurrentEdit in core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditLoadingTest.php
Tests concurrent node edit.

File

core/tests/Drupal/Tests/BrowserTestBase.php, line 292

Class

BrowserTestBase
Provides a test case for functional Drupal tests.

Namespace

Drupal\Tests

Code

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;
}

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