function KernelTestBaseTest::testOutboundHttpRequest

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/KernelTestBaseTest.php \Drupal\KernelTests\KernelTestBaseTest::testOutboundHttpRequest()
  2. 10 core/tests/Drupal/KernelTests/KernelTestBaseTest.php \Drupal\KernelTests\KernelTestBaseTest::testOutboundHttpRequest()
  3. 11.x core/tests/Drupal/KernelTests/KernelTestBaseTest.php \Drupal\KernelTests\KernelTestBaseTest::testOutboundHttpRequest()

Tests that an outbound HTTP request can be performed inside of a test.

File

core/tests/Drupal/KernelTests/KernelTestBaseTest.php, line 171

Class

KernelTestBaseTest
@coversDefaultClass <a href="/api/drupal/core%21tests%21Drupal%21KernelTests%21KernelTestBase.php/class/KernelTestBase/8.9.x" title="Base class for functional integration tests." class="local">\Drupal\KernelTests\KernelTestBase</a>

Namespace

Drupal\KernelTests

Code

public function testOutboundHttpRequest() {
    // The middleware test.http_client.middleware calls drupal_generate_test_ua
    // which checks the DRUPAL_TEST_IN_CHILD_SITE constant, that is not defined
    // in Kernel tests.
    try {
        $this->container
            ->get('http_client')
            ->get('http://example.com');
    } catch (GuzzleException $e) {
        // Ignore any HTTP errors.
    }
}

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