Completed
Push — master ( c7a187...1a4f5e )
by Alexandr
02:57
created

Issue116TestTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 8
dl 0
loc 73
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A Issue116Test::testInternalVariableArgument() 0 69 2
1
<?php
2
3
namespace Youshido\Tests\Issues\Issue116Test;
4
5
use Youshido\GraphQL\Execution\Processor;
6
use Youshido\GraphQL\Schema\Schema;
7
use Youshido\GraphQL\Type\ListType\ListType;
8
use Youshido\GraphQL\Type\NonNullType;
9
use Youshido\GraphQL\Type\Object\ObjectType;
10
use Youshido\GraphQL\Type\Scalar\IntType;
11
use Youshido\GraphQL\Type\Scalar\StringType;
12
13
class Issue116Test extends \PHPUnit_Framework_TestCase
14
{
15
16
    public function testInternalVariableArgument()
17
    {
18
        $schema    = new Schema([
19
            'query' => new ObjectType([
20
                'name'   => 'RootQuery',
21
                'fields' => [
22
                    'connections' => [
23
                        'type'    => new ObjectType([
24
                            'name'   => 'ConnectionType',
25
                            'fields' => [
26
                                'pageInfo' => new ObjectType([
27
                                    'name'   => 'PageInfo',
28
                                    'fields' => [
29
                                        'totalEdges' => new IntType(),
30
                                        'cursors'    => [
31
                                            'type'    => new ListType(new StringType()),
32
                                            'args'    => [
33
                                                'size' => new NonNullType(new IntType()),
34
                                            ],
35
                                            'resolve' => function ($source, $args) {
36
                                                $res = [];
37
                                                foreach (range(1, $args['size']) as $i) {
38
                                                    $res[] = 'Cursor #' . $i;
39
                                                }
40
41
                                                return $res;
42
                                            }
43
                                        ],
44
                                    ]
45
                                ])
46
                            ]
47
                        ]),
48
                        'args'    => [
49
                            'first' => new IntType(),
50
                        ],
51
                        'resolve' => function () {
52
                            return [
53
                                'pageInfo' => [
54
                                    'totalEdges' => 10,
55
                                    'cursors'    => []
56
                                ]
57
                            ];
58
                        }
59
                    ]
60
                ]
61
            ])
62
        ]);
63
        $processor = new Processor($schema);
64
        $response  = $processor->processPayload('
65
query ($size: Int) {
66
  connections(first: 0) {
67
    pageInfo {
68
      totalEdges
69
      cursors (size: $size)
70
    }
71
  }
72
}',
73
            [
74
                'size' => 2,
75
            ])->getResponseData();
76
        $this->assertEquals(['data' => ['connections' => [
77
            'pageInfo' => [
78
                'totalEdges' => 10,
79
                'cursors'    => [
80
                    'Cursor #1', 'Cursor #2'
81
                ]
82
            ],
83
        ]]], $response);
84
    }
85
}