diff --git a/core/modules/simpletest/src/BrowserTestBase.php b/core/modules/simpletest/src/BrowserTestBase.php index 62afe69..e69f9a1 100644 --- a/core/modules/simpletest/src/BrowserTestBase.php +++ b/core/modules/simpletest/src/BrowserTestBase.php @@ -183,18 +183,31 @@ protected $customTranslations; /* - * Mink FQNC for the default driver to use. + * Mink class for the default driver to use. + * + * Shoud be a fully qualified class name that implements + * Behat\Mink\Driver\DriverInterface. + * + * Value can be overriden using the environment variable MINK_DRIVER_ARGS. * * @var string. */ - protected $minkDriverFQCN = '\Behat\Mink\Driver\GoutteDriver'; + protected $minkDefaultDriverClass = '\Behat\Mink\Driver\GoutteDriver'; /* * Mink default driver params. * + * If it's an array its contents are used as constructor params when default + * Mink driver class is instantiated. + * + * Can be overriden using the environment variable MINK_DRIVER_ARGS. In this + * case that variable should be a JSON array, for example: + * '["firefox", null, "http://localhost:4444/wd/hub"]'. + * + * * @var array */ - protected $minkDriverArgs; + protected $minkDefaultDriverArgs; /** * Mink session manager. @@ -219,7 +232,7 @@ protected function initMink() { /** * Gets an instance of the default Mink driver. * - * @return \Drupal\simpletest\minkDriverFQCN + * @return Behat\Mink\Driver\DriverInterface * Instance of default Mink driver. * * @throws \InvalidArgumentException @@ -228,24 +241,26 @@ protected function initMink() { protected function getDefaultDriverInstance() { // Get default driver params from environment if availables. if ($arg_json = getenv('MINK_DRIVER_ARGS')) { - $this->minkDriverArgs = json_decode($arg_json); + $this->minkDefaultDriverArgs = json_decode($arg_json); } // Get and check default driver class from environment if availables. - if ($minkDriverFQCN = getenv('MINK_DRIVER_FQCN')) { - if (class_exists($minkDriverFQCN)) { - $this->minkDriverFQCN = $minkDriverFQCN; + if ($minkDriverClass = getenv('MINK_DRIVER_CLASS')) { + if (class_exists($minkDriverClass)) { + $this->minkDefaultDriverClass = $minkDriverClass; } else { - throw new \InvalidArgumentException("Can't instantiate provided $minkDriverFQCN class by environment as default driver class."); + throw new \InvalidArgumentException("Can't instantiate provided $minkDriverClass class by environment as default driver class."); } } - if (is_array($this->minkDriverArgs)) { - $driver = new $this->minkDriverFQCN($this->minkDriverArgs); + 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->minkDriverFQCN(); + $driver = new $this->minkDefaultDriverClass(); } return $driver; }