You are here

protected function BrowserTestBase::getHttpClient in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/BrowserTestBase.php \Drupal\Tests\BrowserTestBase::getHttpClient()
  2. 9 core/tests/Drupal/Tests/BrowserTestBase.php \Drupal\Tests\BrowserTestBase::getHttpClient()

Obtain the HTTP client for the system under test.

Use this method for arbitrary HTTP requests to the site under test. For most tests, you should not get the HTTP client and instead use navigation methods such as drupalGet() and clickLink() in order to benefit from assertions.

Subclasses which substitute a different Mink driver should override this method and provide a Guzzle client if the Mink driver provides one.

Return value

\GuzzleHttp\ClientInterface The client with BrowserTestBase configuration.

Throws

\RuntimeException If the Mink driver does not support a Guzzle HTTP client, throw an exception.

3 calls to BrowserTestBase::getHttpClient()
DestinationTest::testDestination in core/modules/system/tests/src/Functional/Routing/DestinationTest.php
Tests that $_GET/$_REQUEST['destination'] only contain internal URLs.
SessionHttpsTest::loginHttp in core/modules/system/tests/src/Functional/Session/SessionHttpsTest.php
Log in a user via HTTP.
SessionHttpsTest::loginHttps in core/modules/system/tests/src/Functional/Session/SessionHttpsTest.php
Log in a user via HTTPS.

File

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

Class

BrowserTestBase
Provides a test case for functional Drupal tests.

Namespace

Drupal\Tests

Code

protected function getHttpClient() {

  /** @var \Behat\Mink\Driver\DriverInterface $mink_driver */
  $mink_driver = $this
    ->getSession()
    ->getDriver();
  if ($this
    ->isTestUsingGuzzleClient()) {
    return $mink_driver
      ->getClient()
      ->getClient();
  }
  throw new \RuntimeException('The Mink client type ' . get_class($mink_driver) . ' does not support getHttpClient().');
}