Loading core/lib/Drupal/Core/CoreServiceProvider.php +5 −0 Original line number Diff line number Diff line Loading @@ -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') Loading core/tests/Drupal/KernelTests/KernelTestBaseTest.php +16 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 */ Loading Loading
core/lib/Drupal/Core/CoreServiceProvider.php +5 −0 Original line number Diff line number Diff line Loading @@ -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') Loading
core/tests/Drupal/KernelTests/KernelTestBaseTest.php +16 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 */ Loading