Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — annotations ( a85f92...4ec00b )
by Jérémiah
24:35 queued 10s
created

StarWarsIntrospectionTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 394
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 168
dl 0
loc 394
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testAllowsQueryingTheSchemaForFieldArgs() 0 102 1
A testAllowsQueryingTheSchemaForQueryType() 0 19 1
A testAllowsQueryingTheSchemaForTypes() 0 43 1
A testAllowsQueryingTheSchemaForDocumentation() 0 17 1
A testAllowsQueryingForInterfaceKind() 0 17 1
A testAllowsQueryingForObjectFields() 0 59 1
A testAllowsQueryingTheSchemaForASpecificType() 0 15 1
A testAllowsQueryingForAnObjectKind() 0 17 1
A testAllowsQueryingTheSchemaForNestedObjectFields() 0 77 1
1
<?php
2
3
/*
4
 * This file is part of the OverblogGraphQLPhpGenerator package.
5
 *
6
 * (c) Overblog <http://github.com/overblog/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Overblog\GraphQLGenerator\Tests;
13
14
use GraphQL\GraphQL;
15
16
class StarWarsIntrospectionTest extends AbstractStarWarsTest
17
{
18
    // Star Wars Introspection Tests
19
    // Basic Introspection
20
    // it('Allows querying the schema for types')
21
    public function testAllowsQueryingTheSchemaForTypes()
22
    {
23
        $query = '
24
        query IntrospectionTypeQuery {
25
          __schema {
26
            types {
27
              name
28
            }
29
          }
30
        }
31
        ';
32
        $expected = [
33
            '__schema' => [
34
                'types' => [
35
                    ['name' => 'ID'],
36
                    ['name' => 'String'],
37
                    ['name' => 'Float'],
38
                    ['name' => 'Int'],
39
                    ['name' => 'Boolean'],
40
                    ['name' => '__Schema'],
41
                    ['name' => '__Type'],
42
                    ['name' => '__TypeKind'],
43
                    ['name' => '__Field'],
44
                    ['name' => '__InputValue'],
45
                    ['name' => '__EnumValue'],
46
                    ['name' => '__Directive'],
47
                    ['name' => '__DirectiveLocation'],
48
                    ['name' => 'Query'],
49
                    ['name' => 'HeroInput'],
50
                    ['name' => 'Episode'],
51
                    ['name' => 'Character'],
52
                    ['name' => 'Human'],
53
                    ['name' => 'Droid'],
54
                    ['name' => 'DateTime'],
55
                ]
56
            ]
57
        ];
58
59
        $actual = GraphQL::executeQuery($this->schema, $query)->toArray();
60
        $this->sortSchemaEntry($actual, 'types', 'name');
61
        $this->sortSchemaEntry($expected, 'types', 'name');
62
        $expected = ['data' => $expected];
63
        $this->assertEquals($expected, $actual, \json_encode($actual));
64
    }
65
66
    // it('Allows querying the schema for query type')
67
    public function testAllowsQueryingTheSchemaForQueryType()
68
    {
69
        $query = '
70
        query IntrospectionQueryTypeQuery {
71
          __schema {
72
            queryType {
73
              name
74
            }
75
          }
76
        }
77
        ';
78
        $expected = [
79
            '__schema' => [
80
                'queryType' => [
81
                    'name' => 'Query'
82
                ],
83
            ]
84
        ];
85
        $this->assertValidQuery($query, $expected);
86
    }
87
88
    // it('Allows querying the schema for a specific type')
89
    public function testAllowsQueryingTheSchemaForASpecificType()
90
    {
91
        $query = '
92
        query IntrospectionDroidTypeQuery {
93
          __type(name: "Droid") {
94
            name
95
          }
96
        }
97
        ';
98
        $expected = [
99
            '__type' => [
100
                'name' => 'Droid'
101
            ]
102
        ];
103
        $this->assertValidQuery($query, $expected);
104
    }
105
106
    // it('Allows querying the schema for an object kind')
107
    public function testAllowsQueryingForAnObjectKind()
108
    {
109
        $query = '
110
        query IntrospectionDroidKindQuery {
111
          __type(name: "Droid") {
112
            name
113
            kind
114
          }
115
        }
116
        ';
117
        $expected = [
118
            '__type' => [
119
                'name' => 'Droid',
120
                'kind' => 'OBJECT'
121
            ]
122
        ];
123
        $this->assertValidQuery($query, $expected);
124
    }
125
126
    // it('Allows querying the schema for an interface kind')
127
    public function testAllowsQueryingForInterfaceKind()
128
    {
129
        $query = '
130
        query IntrospectionCharacterKindQuery {
131
          __type(name: "Character") {
132
            name
133
            kind
134
          }
135
        }
136
        ';
137
        $expected = [
138
            '__type' => [
139
                'name' => 'Character',
140
                'kind' => 'INTERFACE'
141
            ]
142
        ];
143
        $this->assertValidQuery($query, $expected);
144
    }
145
146
    // it('Allows querying the schema for object fields')
147
    public function testAllowsQueryingForObjectFields()
148
    {
149
        $query = '
150
        query IntrospectionDroidFieldsQuery {
151
          __type(name: "Droid") {
152
            name
153
            fields {
154
              name
155
              type {
156
                name
157
                kind
158
              }
159
            }
160
          }
161
        }
162
        ';
163
        $expected = [
164
            '__type' => [
165
                'name' => 'Droid',
166
                'fields' => [
167
                    [
168
                        'name' => 'id',
169
                        'type' => [
170
                            'name' => null,
171
                            'kind' => 'NON_NULL'
172
                        ]
173
                    ],
174
                    [
175
                        'name' => 'name',
176
                        'type' => [
177
                            'name' => 'String',
178
                            'kind' => 'SCALAR'
179
                        ]
180
                    ],
181
                    [
182
                        'name' => 'friends',
183
                        'type' => [
184
                            'name' => null,
185
                            'kind' => 'LIST'
186
                        ]
187
                    ],
188
                    [
189
                        'name' => 'appearsIn',
190
                        'type' => [
191
                            'name' => null,
192
                            'kind' => 'LIST'
193
                        ]
194
                    ],
195
                    [
196
                        'name' => 'primaryFunction',
197
                        'type' => [
198
                            'name' => 'String',
199
                            'kind' => 'SCALAR'
200
                        ]
201
                    ]
202
                ]
203
            ]
204
        ];
205
        $this->assertValidQuery($query, $expected);
206
    }
207
208
    // it('Allows querying the schema for nested object fields')
209
    public function testAllowsQueryingTheSchemaForNestedObjectFields()
210
    {
211
        $query = '
212
        query IntrospectionDroidNestedFieldsQuery {
213
          __type(name: "Droid") {
214
            name
215
            fields {
216
              name
217
              type {
218
                name
219
                kind
220
                ofType {
221
                  name
222
                  kind
223
                }
224
              }
225
            }
226
          }
227
        }
228
        ';
229
        $expected = [
230
            '__type' => [
231
                'name' => 'Droid',
232
                'fields' => [
233
                    [
234
                        'name' => 'id',
235
                        'type' => [
236
                            'name' => null,
237
                            'kind' => 'NON_NULL',
238
                            'ofType' => [
239
                                'name' => 'String',
240
                                'kind' => 'SCALAR'
241
                            ]
242
                        ]
243
                    ],
244
                    [
245
                        'name' => 'name',
246
                        'type' => [
247
                            'name' => 'String',
248
                            'kind' => 'SCALAR',
249
                            'ofType' => null
250
                        ]
251
                    ],
252
                    [
253
                        'name' => 'friends',
254
                        'type' => [
255
                            'name' => null,
256
                            'kind' => 'LIST',
257
                            'ofType' => [
258
                                'name' => 'Character',
259
                                'kind' => 'INTERFACE'
260
                            ]
261
                        ]
262
                    ],
263
                    [
264
                        'name' => 'appearsIn',
265
                        'type' => [
266
                            'name' => null,
267
                            'kind' => 'LIST',
268
                            'ofType' => [
269
                                'name' => 'Episode',
270
                                'kind' => 'ENUM'
271
                            ]
272
                        ]
273
                    ],
274
                    [
275
                        'name' => 'primaryFunction',
276
                        'type' => [
277
                            'name' => 'String',
278
                            'kind' => 'SCALAR',
279
                            'ofType' => null
280
                        ]
281
                    ]
282
                ]
283
            ]
284
        ];
285
        $this->assertValidQuery($query, $expected);
286
    }
287
288
    public function testAllowsQueryingTheSchemaForFieldArgs()
289
    {
290
        $query = '
291
        query IntrospectionQueryTypeQuery {
292
          __schema {
293
            queryType {
294
              fields {
295
                name
296
                args {
297
                  name
298
                  description
299
                  type {
300
                    name
301
                    kind
302
                    ofType {
303
                      name
304
                      kind
305
                    }
306
                  }
307
                  defaultValue
308
                }
309
              }
310
            }
311
          }
312
        }
313
        ';
314
        $expected = [
315
            '__schema' => [
316
                'queryType' => [
317
                    'fields' => [
318
                        [
319
                            'name' => 'hero',
320
                            'args' => [
321
                                [
322
                                    'defaultValue' => null,
323
                                    'description' => "If omitted, returns the hero of the whole saga.\nIf provided, returns the hero of that particular episode.\n",
324
                                    'name' => 'episode',
325
                                    'type' => [
326
                                        'kind' => 'INPUT_OBJECT',
327
                                        'name' => 'HeroInput',
328
                                        'ofType' => null,
329
                                    ],
330
                                ],
331
                            ],
332
                        ],
333
                        [
334
                            'name' => 'human',
335
                            'args' => [
336
                                [
337
                                    'name' => 'id',
338
                                    'description' => 'id of the human',
339
                                    'type' => [
340
                                        'kind' => 'NON_NULL',
341
                                        'name' => null,
342
                                        'ofType' => [
343
                                            'kind' => 'SCALAR',
344
                                            'name' => 'String',
345
                                        ],
346
                                    ],
347
                                    'defaultValue' => null,
348
                                ],
349
                            ],
350
                        ],
351
                        [
352
                            'name' => 'droid',
353
                            'args' => [
354
                                [
355
                                    'name' => 'id',
356
                                    'description' => 'id of the droid',
357
                                    'type' => [
358
                                        'kind' => 'NON_NULL',
359
                                        'name' => null,
360
                                        'ofType' =>
361
                                            [
362
                                                'kind' => 'SCALAR',
363
                                                'name' => 'String',
364
                                            ],
365
                                    ],
366
                                    'defaultValue' => null,
367
                                ],
368
                            ],
369
                        ],
370
                        [
371
                            'name' => 'dateTime',
372
                            'args' => [
373
                                [
374
                                    'name' => 'dateTime',
375
                                    'description' => null,
376
                                    'type' => [
377
                                        'name' => 'DateTime',
378
                                        'kind' => 'SCALAR',
379
                                        'ofType' => null,
380
                                    ],
381
                                    'defaultValue' => null,
382
                                ]
383
                            ],
384
                        ],
385
                    ],
386
                ],
387
            ],
388
        ];
389
        $this->assertValidQuery($query, $expected);
390
    }
391
392
    // it('Allows querying the schema for documentation')
393
    public function testAllowsQueryingTheSchemaForDocumentation()
394
    {
395
        $query = '
396
        query IntrospectionDroidDescriptionQuery {
397
          __type(name: "Droid") {
398
            name
399
            description
400
          }
401
        }
402
        ';
403
        $expected = [
404
            '__type' => [
405
                'name' => 'Droid',
406
                'description' => 'A mechanical creature in the Star Wars universe.'
407
            ]
408
        ];
409
        $this->assertValidQuery($query, $expected);
410
    }
411
}
412