ExternalRequestTest.php in GraphQL 8.3
File
modules/graphql_core/tests/src/Kernel/Routing/ExternalRequestTest.php
View source
<?php
namespace Drupal\Tests\graphql_core\Kernel\Routing;
use Drupal\Tests\graphql_core\Kernel\GraphQLCoreTestBase;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Psr7\Response;
class ExternalRequestTest extends GraphQLCoreTestBase {
public static $modules = [
'graphql_core',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('user');
}
public function testExternalRequests() {
$client = $this
->prophesize(ClientInterface::class);
$client
->request('GET', 'http://drupal.graphql')
->willReturn(new Response(200, [
'graphql' => 'test',
], '<p>GraphQL is awesome!</p>'));
$this->container
->set('http_client', $client
->reveal());
$metadata = $this
->defaultCacheMetaData();
$this
->assertResults($this
->getQueryFromFile('external_requests.gql'), [], [
'route' => [
'request' => [
'code' => 200,
'content' => '<p>GraphQL is awesome!</p>',
'header' => 'test',
],
],
], $metadata);
}
}