StarWarsTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 201
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 201
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testSchema() 0 9 1
A testInvalidVariableType() 0 28 1
B dataProvider() 0 150 1
1
<?php
2
/**
3
 * Date: 07.12.15
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\Tests\StarWars;
9
10
11
use Youshido\GraphQL\Execution\Processor;
12
use Youshido\Tests\StarWars\Schema\StarWarsSchema;
13
14
class StarWarsTest extends \PHPUnit_Framework_TestCase
15
{
16
17
    /**
18
     * @param $query
19
     * @param $validResult
20
     * @param $variables
21
     *
22
     * @dataProvider dataProvider
23
     */
24
    public function testSchema($query, $validResult, $variables)
25
    {
26
        $processor = new Processor(new StarWarsSchema());
27
28
        $processor->processPayload($query, $variables);
29
30
        $responseData = $processor->getResponseData();
31
        $this->assertEquals($validResult, $responseData);
32
    }
33
34
    public function testInvalidVariableType()
35
    {
36
        $processor = new Processor(new StarWarsSchema());
37
38
        $processor->processPayload(
39
            'query($someId: Int){
40
                human(id: $someId) {
41
                    name
42
                }
43
            }', ['someId' => 1]
44
        );
45
46
        $data = $processor->getResponseData();
47
        $this->assertEquals($data, [
48
            'data'   => ['human' => null],
49
            'errors' => [
50
                [
51
                    'message'   => 'Invalid variable "someId" type, allowed type is "ID"',
52
                    'locations' => [
53
                        [
54
                            'line'   => 1,
55
                            'column' => 7
56
                        ]
57
                    ]
58
                ]
59
            ]
60
        ]);
61
    }
62
63
64
    public function dataProvider()
65
    {
66
        return [
67
            [
68
                'query CheckTypeOfLuke {
69
                  hero(episode: EMPIRE) {
70
                    __typename,
71
                    name
72
                  }
73
                }',
74
                [
75
                    'data' => [
76
                        'hero' => [
77
                            '__typename' => 'Human',
78
                            'name'       => 'Luke Skywalker'
79
                        ],
80
                    ]
81
                ],
82
                []
83
            ],
84
            [
85
                'query {
86
                  hero {
87
                    name
88
                  }
89
              }',
90
                ['data' => [
91
                    'hero' => [
92
                        'name' => 'R2-D2'
93
                    ]
94
                ]],
95
                []
96
            ],
97
            [
98
                'query {
99
                  hero {
100
                    id,
101
                    name,
102
                    friends {
103
                      name
104
                    }
105
                  }
106
                }',
107
                ['data' => [
108
                    'hero' => [
109
                        'id'      => '2001',
110
                        'name'    => 'R2-D2',
111
                        'friends' => [
112
                            [
113
                                'name' => 'Luke Skywalker',
114
                            ],
115
                            [
116
                                'name' => 'Han Solo',
117
                            ],
118
                            [
119
                                'name' => 'Leia Organa',
120
                            ],
121
                        ]
122
                    ]
123
                ]],
124
                []
125
            ],
126
            [
127
                '{
128
                  hero {
129
                    name,
130
                    friends {
131
                      name,
132
                      appearsIn,
133
                      friends {
134
                        name
135
                      }
136
                    }
137
                  }
138
                }',
139
                [
140
                    'data' => [
141
                        'hero' => [
142
                            'name'    => 'R2-D2',
143
                            'friends' => [
144
                                [
145
                                    'name'      => 'Luke Skywalker',
146
                                    'appearsIn' => ['NEWHOPE', 'EMPIRE', 'JEDI',],
147
                                    'friends'   => [
148
                                        ['name' => 'Han Solo',],
149
                                        ['name' => 'Leia Organa',],
150
                                        ['name' => 'C-3PO',],
151
                                        ['name' => 'R2-D2',],
152
                                    ],
153
                                ],
154
                                [
155
                                    'name'      => 'Han Solo',
156
                                    'appearsIn' => ['NEWHOPE', 'EMPIRE', 'JEDI'],
157
                                    'friends'   => [
158
                                        ['name' => 'Luke Skywalker',],
159
                                        ['name' => 'Leia Organa'],
160
                                        ['name' => 'R2-D2',],
161
                                    ]
162
                                ],
163
                                [
164
                                    'name'      => 'Leia Organa',
165
                                    'appearsIn' => ['NEWHOPE', 'EMPIRE', 'JEDI'],
166
                                    'friends'   =>
167
                                        [
168
                                            ['name' => 'Luke Skywalker',],
169
                                            ['name' => 'Han Solo',],
170
                                            ['name' => 'C-3PO',],
171
                                            ['name' => 'R2-D2',],
172
                                        ],
173
                                ],
174
                            ],
175
                        ]
176
                    ]
177
                ],
178
                []
179
            ],
180
            [
181
                '{
182
                  human(id: "1000") {
183
                    name
184
                  }
185
                }',
186
                [
187
                    'data' => [
188
                        'human' => [
189
                            'name' => 'Luke Skywalker'
190
                        ]
191
                    ]
192
                ],
193
                []
194
            ],
195
            [
196
                'query($someId: ID){
197
                  human(id: $someId) {
198
                    name
199
                  }
200
                }',
201
                [
202
                    'data' => [
203
                        'human' => [
204
                            'name' => 'Luke Skywalker'
205
                        ]
206
                    ]
207
                ],
208
                [
209
                    'someId' => '1000'
210
                ]
211
            ]
212
        ];
213
    }
214
}
215