You are here

public function DrupalTestBrowser::setClient in Drupal 9

Sets the Guzzle client.

Parameters

\GuzzleHttp\ClientInterface $client: The Guzzle client.

Return value

$this

File

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

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