Issue #2571475 by mglaman, tstoeckler, tedbow, eiriksm, Jaesin, phenaproxima, alexpott: Outbound HTTP requests fail with KernelTestBase
parent
1749b10a30
commit
51e0c383e1
|
@ -131,6 +131,11 @@ class CoreServiceProvider implements ServiceProviderInterface, ServiceModifierIn
|
|||
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')
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Drupal\KernelTests;
|
|||
|
||||
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 @@ class KernelTestBaseTest extends KernelTestBase {
|
|||
$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…
Reference in New Issue