Completed
Pull Request — 8.x-3.x (#501)
by Philipp
04:28
created

ExternalRequestTest::testExternalRequests()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
nc 1
nop 0
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\Tests\graphql_core\Kernel\Routing;
4
5
use Drupal\Tests\graphql_core\Kernel\GraphQLCoreTestBase;
6
use GuzzleHttp\ClientInterface;
7
use GuzzleHttp\Psr7\Response;
8
9
/**
10
 * Test external requests.
11
 *
12
 * @group graphql_core
13
 */
14
class ExternalRequestTest extends GraphQLCoreTestBase {
15
16
  /**
17
   * {@inheritdoc}
18
   */
19
  public static $modules = ['graphql_core'];
20
21
  /**
22
   * {@inheritdoc}
23
   */
24
  protected function setUp() {
25
    parent::setUp();
26
    $this->installEntitySchema('user');
27
  }
28
29
  /**
30
   * Test external requests.
31
   */
32
  public function testExternalRequests() {
33
34
    $client = $this->prophesize(ClientInterface::class);
35
    $client->request('GET', 'http://drupal.graphql')->willReturn(new Response(
36
      200,
37
      ['graphql' => 'test'],
38
      '<p>GraphQL is awesome!</p>'
39
    ));
40
41
    $this->container->set('http_client', $client->reveal());
42
43
    // TODO: Check cache metadata.
44
    // Add cache information from external response?
45
    $metadata = $this->defaultCacheMetaData();
46
47
    $this->assertResults($this->getQueryFromFile('external_requests.gql'), [], [
48
      'route' => [
49
        'request' => [
50
          'code' => 200,
51
          'content' => '<p>GraphQL is awesome!</p>',
52
          'header' => 'test',
53
        ],
54
      ],
55
    ], $metadata);
56
  }
57
58
}
59