Completed
Push — master ( 7a0180...875ce0 )
by Alexandr
02:39
created

Issue149Test::testInternalVariableArgument()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 84
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 84
rs 8.7169
c 0
b 0
f 0
cc 1
eloc 45
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\IdType;
11
use Youshido\GraphQL\Type\Scalar\IntType;
12
use Youshido\GraphQL\Type\Scalar\StringType;
13
14
class Issue149Test extends \PHPUnit_Framework_TestCase
15
{
16
    public function testInternalVariableArgument()
17
    {
18
        $schema    = new Schema([
19
            'query' => new ObjectType([
20
                'name'   => 'RootQuery',
21
                'fields' => [
22
                    'user' => [
23
                        'type'    => new ObjectType([
24
                            'name'   => 'User',
25
                            'fields' => [
26
                                'id'      => new IdType(),
27
                                'name'    => new StringType(),
28
                                'age'     => new IntType(),
29
                                'friends' => new ListType(new ObjectType([
30
                                    'name'   => 'UserFriend',
31
                                    'fields' => [
32
                                        'id'   => new IdType(),
33
                                        'name' => new StringType(),
34
                                        'age'  => new IntType(),
35
                                    ],
36
                                ])),
37
                            ],
38
                        ]),
39
                        'resolve' => function () {
40
                            return [
41
                                'id'      => 1,
42
                                'name'    => 'John',
43
                                'age'     => 30,
44
                                'friends' => [
45
                                    [
46
                                        'id'   => 2,
47
                                        'name' => 'Friend 1',
48
                                        'age'  => 31,
49
                                    ],
50
                                    [
51
                                        'id'   => 3,
52
                                        'name' => 'Friend 2',
53
                                        'age'  => 32,
54
                                    ],
55
                                ],
56
                            ];
57
                        },
58
                    ],
59
                ],
60
            ]),
61
        ]);
62
        $processor = new Processor($schema);
63
        $response  = $processor->processPayload('
64
{
65
    user {
66
        id
67
        name
68
        friends {
69
            id
70
            name
71
        }
72
    }
73
    user {
74
        id
75
        age
76
        friends {
77
            id
78
            age
79
        }
80
    }
81
}')->getResponseData();
82
        $this->assertEquals(['data' => ['user' => [
83
            'id'   => '1',
84
            'name' => 'John',
85
            'age'  => 30,
86
            'friends' => [
87
                [
88
                    'id'   => 2,
89
                    'name' => 'Friend 1',
90
                    'age'  => 31,
91
                ],
92
                [
93
                    'id'   => 3,
94
                    'name' => 'Friend 2',
95
                    'age'  => 32,
96
                ],
97
            ]
98
        ]]], $response);
99
    }
100
}