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

ExternalRequestTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
B testExternalRequests() 0 25 1
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