Unverified Commit 51e0c383 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2571475 by mglaman, tstoeckler, tedbow, eiriksm, Jaesin, phenaproxima,...

Issue #2571475 by mglaman, tstoeckler, tedbow, eiriksm, Jaesin, phenaproxima, alexpott: Outbound HTTP requests fail with KernelTestBase
parent 1749b10a
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -131,6 +131,11 @@ protected function registerTest(ContainerBuilder $container) {
    if (!drupal_valid_test_ua()) {
      return;
    }
    // The test middleware is not required for kernel tests as there is no child
    // site. DRUPAL_TEST_IN_CHILD_SITE is not defined in this case.
    if (!defined('DRUPAL_TEST_IN_CHILD_SITE')) {
      return;
    }
    // Add the HTTP request middleware to Guzzle.
    $container
      ->register('test.http_client.middleware', 'Drupal\Core\Test\HttpClientMiddleware\TestHttpClientMiddleware')
+16 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

use Drupal\Component\FileCache\FileCacheFactory;
use Drupal\Core\Database\Database;
use GuzzleHttp\Exception\GuzzleException;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\visitor\vfsStreamStructureVisitor;
use PHPUnit\Framework\SkippedTestError;
@@ -164,6 +165,21 @@ public function testSubsequentContainerIsolation() {
    $this->assertNull($this->installConfig('user'));
  }

  /**
   * Tests that an outbound HTTP request can be performed inside of a test.
   */
  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.
    }
  }

  /**
   * @covers ::render
   */