You are here

protected function BrowserTestBase::getDefaultDriverInstance in Drupal 8

Same name and namespace in other branches
  1. 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.

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 Quick Edit on a node that was concurrently edited on the full node form.

File

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

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