function DrupalTestBrowser::setClient

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/DrupalTestBrowser.php \Drupal\Tests\DrupalTestBrowser::setClient()
  2. 10 core/tests/Drupal/Tests/DrupalTestBrowser.php \Drupal\Tests\DrupalTestBrowser::setClient()

Sets the Guzzle client.

Parameters

\GuzzleHttp\ClientInterface $client: The Guzzle client.

Return value

$this

File

core/tests/Drupal/Tests/DrupalTestBrowser.php, line 39

Class

DrupalTestBrowser
Enables a BrowserKitDriver mink driver to use a Guzzle client.

Namespace

Drupal\Tests

Code

public function setClient(ClientInterface $client) {
    $this->client = $client;
    if ($this->getServerParameter('HTTP_HOST', NULL) !== NULL || ($base_uri = $client->getConfig('base_uri') === NULL)) {
        return $this;
    }
    $path = $base_uri->getPath();
    if ($path !== '' && $path !== '/') {
        throw new \InvalidArgumentException('Setting a path in the Guzzle "base_uri" config option is not supported by DrupalTestBrowser.');
    }
    if ($this->getServerParameter('HTTPS', NULL) === NULL && $base_uri->getScheme() === 'https') {
        $this->setServerParameter('HTTPS', 'on');
    }
    $host = $base_uri->getHost();
    if (($port = $base_uri->getPort()) !== NULL) {
        $host .= ":{$port}";
    }
    $this->setServerParameter('HTTP_HOST', $host);
    return $this;
}

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