You are here

public function ExternalRequestTest::testExternalRequests in GraphQL 8.3

Test external requests.

File

modules/graphql_core/tests/src/Kernel/Routing/ExternalRequestTest.php, line 32

Class

ExternalRequestTest
Test external requests.

Namespace

Drupal\Tests\graphql_core\Kernel\Routing

Code

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());

  // Add cache information from external response?
  $metadata = $this
    ->defaultCacheMetaData();
  $this
    ->assertResults($this
    ->getQueryFromFile('external_requests.gql'), [], [
    'route' => [
      'request' => [
        'code' => 200,
        'content' => '<p>GraphQL is awesome!</p>',
        'header' => 'test',
      ],
    ],
  ], $metadata);
}