Completed
Push — master ( 48a1e6...3c3b08 )
by Portey
03:48
created

ProcessorTest::testInit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/*
3
 * This file is a part of GraphQL project.
4
 *
5
 * @author Alexandr Viniychuk <[email protected]>
6
 * created: 11:02 PM 5/13/16
7
 */
8
9
namespace Youshido\Tests\Schema;
10
11
12
use Youshido\GraphQL\Execution\Processor;
13
use Youshido\GraphQL\Execution\ResolveInfo;
14
use Youshido\GraphQL\Execution\Visitor\MaxComplexityQueryVisitor;
15
use Youshido\GraphQL\Field\Field;
16
use Youshido\GraphQL\Schema\Schema;
17
use Youshido\GraphQL\Type\Enum\EnumType;
18
use Youshido\GraphQL\Type\ListType\ListType;
19
use Youshido\GraphQL\Type\NonNullType;
20
use Youshido\GraphQL\Type\Object\ObjectType;
21
use Youshido\GraphQL\Type\Scalar\BooleanType;
22
use Youshido\GraphQL\Type\Scalar\IdType;
23
use Youshido\GraphQL\Type\Scalar\IntType;
24
use Youshido\GraphQL\Type\Scalar\StringType;
25
use Youshido\GraphQL\Type\Union\UnionType;
26
use Youshido\Tests\DataProvider\TestEmptySchema;
27
use Youshido\Tests\DataProvider\TestEnumType;
28
use Youshido\Tests\DataProvider\TestInterfaceType;
29
use Youshido\Tests\DataProvider\TestObjectType;
30
use Youshido\Tests\DataProvider\TestSchema;
31
32
class ProcessorTest extends \PHPUnit_Framework_TestCase
33
{
34
35
    private $_counter = 0;
36
37
    /**
38
     * @expectedException \Youshido\GraphQL\Validator\Exception\ConfigurationException
39
     * @expectedExceptionMessage Schema has to have fields
40
     */
41
    public function testInit()
42
    {
43
        new Processor(new TestEmptySchema());
44
    }
45
46
    public function testEmptyQueries()
47
    {
48
        $processor = new Processor(new TestSchema());
49
        $processor->processPayload('');
50
        $this->assertEquals(['errors' => [
51
            ['message' => 'Must provide an operation.']
52
        ]], $processor->getResponseData());
53
54
        $processor->processPayload('{ me { name } }');
55
        $this->assertEquals(['data' => [
56
            'me' => ['name' => 'John']
57
        ]], $processor->getResponseData());
58
59
    }
60
61
    public function testNestedVariables()
62
    {
63
        $processor    = new Processor(new TestSchema());
64
        $noArgsQuery  = '{ me { echo(value:"foo") } }';
65
        $expectedData = ['data' => ['me' => ['echo' => 'foo']]];
66
        $processor->processPayload($noArgsQuery, ['value' => 'foo']);
67
        $this->assertEquals($expectedData, $processor->getResponseData());
68
69
        $parameterizedFieldQuery =
70
            'query nestedFieldQuery($value:String!){
71
          me {
72
            echo(value:$value)
73
          }
74
        }';
75
        $processor->processPayload($parameterizedFieldQuery, ['value' => 'foo']);
76
        $this->assertEquals($expectedData, $processor->getResponseData());
77
78
        $parameterizedQueryQuery =
79
            'query nestedQueryQuery($value:Int){
80
          me {
81
            location(noop:$value) {
82
              address
83
            }
84
          }
85
        }';
86
        $processor->processPayload($parameterizedQueryQuery, ['value' => 1]);
87
        $this->assertArrayNotHasKey('errors', $processor->getResponseData());
88
    }
89
90 View Code Duplication
    public function testListNullResponse()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
91
    {
92
        $processor = new Processor(new Schema([
93
            'query' => new ObjectType([
94
                'name'   => 'RootQuery',
95
                'fields' => [
96
                    'list' => [
97
                        'type'    => new ListType(new StringType()),
98
                        'resolve' => function () {
99
                            return null;
100
                        }
101
                    ]
102
                ]
103
            ])
104
        ]));
105
        $data      = $processor->processPayload(' { list }')->getResponseData();
106
        $this->assertEquals(['data' => ['list' => null]], $data);
107
    }
108
109
110 View Code Duplication
    public function testSubscriptionNullResponse()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
111
    {
112
        $processor = new Processor(new Schema([
113
            'query' => new ObjectType([
114
                'name'   => 'RootQuery',
115
                'fields' => [
116
                    'list' => [
117
                        'type'    => new ListType(new StringType()),
118
                        'resolve' => function () {
119
                            return null;
120
                        }
121
                    ]
122
                ]
123
            ])
124
        ]));
125
        $data      = $processor->processPayload(' { __schema { subscriptionType { name } } }')->getResponseData();
126
        $this->assertEquals(['data' => ['__schema' => ['subscriptionType' => null]]], $data);
127
    }
128
129
    public function testSchemaOperations()
130
    {
131
        $schema    = new Schema([
132
            'query' => new ObjectType([
133
                'name'   => 'RootQuery',
134
                'fields' => [
135
                    'me'                => [
136
                        'type'    => new ObjectType([
137
                            'name'   => 'User',
138
                            'fields' => [
139
                                'firstName' => [
140
                                    'type'    => new StringType(),
141
                                    'args'    => [
142
                                        'shorten' => new BooleanType()
143
                                    ],
144
                                    'resolve' => function ($value, $args) {
145
                                        return empty($args['shorten']) ? $value['firstName'] : $value['firstName'];
146
                                    }
147
                                ],
148
                                'id_alias'  => [
149
                                    'type'    => new IdType(),
150
                                    'resolve' => function ($value) {
151
                                        return $value['id'];
152
                                    }
153
                                ],
154
                                'lastName'  => new StringType(),
155
                                'code'      => new StringType(),
156
                            ]
157
                        ]),
158
                        'resolve' => function ($value, $args) {
159
                            $data = ['id' => '123', 'firstName' => 'John', 'code' => '007'];
160
                            if (!empty($args['upper'])) {
161
                                foreach ($data as $key => $value) {
162
                                    $data[$key] = strtoupper($value);
163
                                }
164
                            }
165
166
                            return $data;
167
                        },
168
                        'args'    => [
169
                            'upper' => [
170
                                'type'    => new BooleanType(),
171
                                'default' => false
172
                            ]
173
                        ]
174
                    ],
175
                    'randomUser'        => [
176
                        'type'    => new TestObjectType(),
177
                        'resolve' => function () {
178
                            return ['invalidField' => 'John'];
179
                        }
180
                    ],
181
                    'invalidValueQuery' => [
182
                        'type'    => new TestObjectType(),
183
                        'resolve' => function () {
184
                            return 'stringValue';
185
                        }
186
                    ],
187
                    'labels'            => [
188
                        'type'    => new ListType(new StringType()),
189
                        'resolve' => function () {
190
                            return ['one', 'two'];
191
                        }
192
                    ]
193
                ],
194
            ])
195
        ]);
196
        $processor = new Processor($schema);
197
198
        $processor->processPayload('{ me { firstName } }');
199
        $this->assertEquals(['data' => ['me' => ['firstName' => 'John']]], $processor->getResponseData());
200
201
        $processor->processPayload('{ me { id_alias } }');
202
        $this->assertEquals(['data' => ['me' => ['id_alias' => '123']]], $processor->getResponseData());
203
204
        $processor->processPayload('{ me { firstName, lastName } }');
205
        $this->assertEquals(['data' => ['me' => ['firstName' => 'John', 'lastName' => null]]], $processor->getResponseData());
206
207
        $processor->processPayload('{ me { code } }');
208
        $this->assertEquals(['data' => ['me' => ['code' => 7]]], $processor->getResponseData());
209
210
        $processor->processPayload('{ me(upper:true) { firstName } }');
211
        $this->assertEquals(['data' => ['me' => ['firstName' => 'JOHN']]], $processor->getResponseData());
212
213
        $processor->processPayload('{ labels }');
214
        $this->assertEquals(['data' => ['labels' => ['one', 'two']]], $processor->getResponseData());
215
216
        $schema->getMutationType()
217
            ->addField(new Field([
218
                'name'    => 'increaseCounter',
219
                'type'    => new IntType(),
220
                'resolve' => function ($value, $args, ResolveInfo $info) {
0 ignored issues
show
Unused Code introduced by
The parameter $info is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
221
                    return $this->_counter += $args['amount'];
222
                },
223
                'args'    => [
224
                    'amount' => [
225
                        'type'    => new IntType(),
226
                        'default' => 1
227
                    ]
228
                ]
229
            ]))->addField(new Field([
230
                'name'    => 'invalidResolveTypeMutation',
231
                'type'    => new NonNullType(new IntType()),
232
                'resolve' => function () {
233
                    return null;
234
                }
235
            ]))->addField(new Field([
236
                'name'    => 'interfacedMutation',
237
                'type'    => new TestInterfaceType(),
238
                'resolve' => function () {
239
                    return ['name' => 'John'];
240
                }
241
            ]));
242
        $processor->processPayload('mutation { increaseCounter }');
243
        $this->assertEquals(['data' => ['increaseCounter' => 1]], $processor->getResponseData());
244
245
        $processor->processPayload('mutation { invalidMutation }');
246
        $this->assertEquals(['errors' => [['message' => 'Field "invalidMutation" not found in type "RootSchemaMutation"']]], $processor->getResponseData());
247
248
        $processor->processPayload('mutation { increaseCounter(noArg: 2) }');
249
        $this->assertEquals(['errors' => [['message' => 'Unknown argument "noArg" on field "increaseCounter"']]], $processor->getResponseData());
250
251
        $processor->processPayload('mutation { increaseCounter(amount: 2) { invalidProp } }');
252
        $this->assertEquals(['errors' => [['message' => 'Fields are not found in query "increaseCounter"']], 'data' => ['increaseCounter' => null]], $processor->getResponseData());
253
254
        $processor->processPayload('mutation { increaseCounter(amount: 2) }');
255
        $this->assertEquals(['data' => ['increaseCounter' => 5]], $processor->getResponseData());
256
257
        $processor->processPayload('{ invalidQuery }');
258
        $this->assertEquals(['errors' => [['message' => 'Field "invalidQuery" not found in type "RootQuery"']]], $processor->getResponseData());
259
260
        $processor->processPayload('{ invalidValueQuery { id } }');
261
        $this->assertEquals(['errors' => [['message' => 'Not valid value for OBJECT field invalidValueQuery']], 'data' => ['invalidValueQuery' => null]], $processor->getResponseData());
262
263
        $processor->processPayload('{ me { firstName(shorten: true), middle }}');
264
        $this->assertEquals(['errors' => [['message' => 'Field "middle" is not found in type "User"']], 'data' => ['me' => null]], $processor->getResponseData());
265
266
        $processor->processPayload('{ randomUser { region }}');
267
        $this->assertEquals(['errors' => [['message' => 'Property "region" not found in resolve result']]], $processor->getResponseData());
268
269
        $processor->processPayload('mutation { invalidResolveTypeMutation }');
270
        $this->assertEquals(['errors' => [['message' => 'Cannot return null for non-nullable field invalidResolveTypeMutation']], 'data' => ['invalidResolveTypeMutation' => null]], $processor->getResponseData());
271
272
        $processor->processPayload('mutation { user:interfacedMutation { name }  }');
273
        $this->assertEquals(['data' => ['user' => ['name' => 'John']]], $processor->getResponseData());
274
    }
275
276
    public function testEnumType()
277
    {
278
        $processor = new Processor(new Schema([
279
            'query' => new ObjectType([
280
                'name'   => 'RootQuery',
281
                'fields' => [
282
                    'test' => [
283
                        'args'    => [
284
                            'argument1' => new NonNullType(new EnumType([
285
                                'name'   => 'TestEnumType',
286
                                'values' => [
287
                                    [
288
                                        'name'  => 'VALUE1',
289
                                        'value' => 'val1'
290
                                    ],
291
                                    [
292
                                        'name'  => 'VALUE2',
293
                                        'value' => 'val2'
294
                                    ]
295
                                ]
296
                            ]))
297
                        ],
298
                        'type'    => new StringType(),
299
                        'resolve' => function ($value, $args) {
300
                            return $args['argument1'];
301
                        }
302
                    ]
303
                ]
304
            ])
305
        ]));
306
307
        $processor->processPayload('{ test }');
308
        $response = $processor->getResponseData();
309
        $this->assertEquals(['errors' => [['message' => 'Require "argument1" arguments to query "test"']]], $response);
310
311
        $processor->processPayload('{ alias: test() }');
312
        $response = $processor->getResponseData();
313
        $this->assertEquals(['errors' => [['message' => 'Require "argument1" arguments to query "test"']]], $response);
314
315
        $processor->processPayload('{ alias: test(argument1: VALUE4) }');
316
        $response = $processor->getResponseData();
317
        $this->assertEquals(['errors' => [['message' => 'Not valid type for argument "argument1" in query "test"']]], $response);
318
319
        $processor->processPayload('{ alias: test(argument1: VALUE1) }');
320
        $response = $processor->getResponseData();
321
        $this->assertEquals(['data' => ['alias' => 'val1']], $response);
322
    }
323
324
    public function testListEnumsSchemaOperations()
325
    {
326
        $processor = new Processor(new Schema([
327
            'query' => new ObjectType([
328
                'name'   => 'RootQuery',
329
                'fields' => [
330
                    'listQuery'                 => [
331
                        'type'    => new ListType(new TestEnumType()),
332
                        'resolve' => function () {
333
                            return 'invalid list';
334
                        }
335
                    ],
336
                    'listEnumQuery'             => [
337
                        'type'    => new ListType(new TestEnumType()),
338
                        'resolve' => function () {
339
                            return ['invalid enum'];
340
                        }
341
                    ],
342
                    'invalidEnumQuery'          => [
343
                        'type'    => new TestEnumType(),
344
                        'resolve' => function () {
345
                            return 'invalid enum';
346
                        }
347
                    ],
348
                    'enumQuery'                 => [
349
                        'type'    => new TestEnumType(),
350
                        'resolve' => function () {
351
                            return 1;
352
                        }
353
                    ],
354
                    'invalidNonNullQuery'       => [
355
                        'type'    => new NonNullType(new IntType()),
356
                        'resolve' => function () {
357
                            return null;
358
                        }
359
                    ],
360
                    'invalidNonNullInsideQuery' => [
361
                        'type'    => new NonNullType(new IntType()),
362
                        'resolve' => function () {
363
                            return 'hello';
364
                        }
365
                    ],
366
                    'objectQuery'               => [
367
                        'type'    => new TestObjectType(),
368
                        'resolve' => function () {
369
                            return ['name' => 'John'];
370
                        }
371
                    ],
372
                    'deepObjectQuery'           => [
373
                        'type'    => new ObjectType([
374
                            'name'   => 'deepObject',
375
                            'fields' => [
376
                                'object' => new TestObjectType(),
377
                                'enum'   => new TestEnumType(),
378
                            ],
379
                        ]),
380
                        'resolve' => function () {
381
                            return [
382
                                'object' => [
383
                                    'name' => 'John'
384
                                ],
385
                                'enum'   => 1
386
                            ];
387
                        },
388
                    ],
389
                ]
390
            ])
391
        ]));
392
393
        $processor->processPayload('{ listQuery }');
394
        $this->assertEquals(['errors' => [
395
            ['message' => 'Not valid value for LIST field listQuery']
396
        ], 'data'                     => ['listQuery' => null]], $processor->getResponseData());
397
398
        $processor->processPayload('{ listEnumQuery }');
399
        $this->assertEquals(['errors' => [
400
            ['message' => 'Not valid resolve value in listEnumQuery field']
401
        ], 'data'                     => ['listEnumQuery' => [null]]], $processor->getResponseData());
402
403
        $processor->processPayload('{ invalidEnumQuery }');
404
        $this->assertEquals(['errors' => [
405
            ['message' => 'Not valid value for ENUM field invalidEnumQuery']
406
        ], 'data'                     => ['invalidEnumQuery' => null]], $processor->getResponseData());
407
408
        $processor->processPayload('{ enumQuery }');
409
        $this->assertEquals(['data' => ['enumQuery' => 'FINISHED']], $processor->getResponseData());
410
411
        $processor->processPayload('{ invalidNonNullQuery }');
412
        $this->assertEquals(['errors' => [
413
            ['message' => 'Cannot return null for non-nullable field invalidNonNullQuery']
414
        ], 'data'                     => ['invalidNonNullQuery' => null]], $processor->getResponseData());
415
416
        $processor->processPayload('{ invalidNonNullInsideQuery }');
417
        $this->assertEquals(['errors' => [
418
            ['message' => 'Not valid value for SCALAR field invalidNonNullInsideQuery']
419
        ], 'data'                     => ['invalidNonNullInsideQuery' => null]], $processor->getResponseData());
420
421
        $processor->processPayload('{ test:deepObjectQuery { object { name } } }');
422
        $this->assertEquals(['data' => ['test' => ['object' => ['name' => 'John']]]], $processor->getResponseData());
423
    }
424
425
    public function testTypedFragment()
426
    {
427
428
        $object1 = new ObjectType([
429
            'name'   => 'Object1',
430
            'fields' => [
431
                'id' => ['type' => 'int', 'cost' => 13]
432
            ]
433
        ]);
434
435
        $object2 = new ObjectType([
436
            'name'   => 'Object2',
437
            'fields' => [
438
                'name' => ['type' => 'string']
439
            ]
440
        ]);
441
442
        $object3 = new ObjectType([
443
            'name'   => 'Object3',
444
            'fields' => [
445
                'name' => ['type' => 'string']
446
            ]
447
        ]);
448
449
        $union        = new UnionType([
450
            'name'        => 'TestUnion',
451
            'types'       => [$object1, $object2],
452
            'resolveType' => function ($object) use ($object1, $object2) {
453
                if (isset($object['id'])) {
454
                    return $object1;
455
                }
456
457
                return $object2;
458
            }
459
        ]);
460
        $invalidUnion = new UnionType([
461
            'name'        => 'TestUnion',
462
            'types'       => [$object1, $object2],
463
            'resolveType' => function ($object) use ($object3) {
0 ignored issues
show
Unused Code introduced by
The parameter $object is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
464
                return $object3;
465
            }
466
        ]);
467
        $processor    = new Processor(new Schema([
468
            'query' => new ObjectType([
469
                'name'   => 'RootQuery',
470
                'fields' => [
471
                    'union'        => [
472
                        'type'    => $union,
473
                        'args'    => [
474
                            'type' => ['type' => 'string']
475
                        ],
476
                        'cost'    => 10,
477
                        'resolve' => function ($value, $args) {
478
                            if ($args['type'] == 'object1') {
479
                                return [
480
                                    'id' => 43
481
                                ];
482
                            } else {
483
                                return [
484
                                    'name' => 'name resolved'
485
                                ];
486
                            }
487
                        }
488
                    ],
489
                    'invalidUnion' => [
490
                        'type'    => $invalidUnion,
491
                        'resolve' => function () {
492
                            return ['name' => 'name resolved'];
493
                        }
494
                    ],
495
                ]
496
            ])
497
        ]));
498
        $processor->processPayload('{ union(type: "object1") { ... on Object2 { id } } }');
499
        $this->assertEquals(['data' => ['union' => []]], $processor->getResponseData());
500
501
        $processor->processPayload('{ union(type: "object1") { ... on Object1 { name } } }');
502
        $this->assertEquals([
503
            'data'   => [
504
                'union' => []
505
            ],
506
            'errors' => [
507
                ['message' => 'Field "name" is not found in type "Object1"']
508
            ]
509
        ], $processor->getResponseData());
510
511
        $processor->processPayload('{ union(type: "object1") { ... on Object1 { id } } }');
512
        $this->assertEquals(['data' => ['union' => ['id' => 43]]], $processor->getResponseData());
513
514
        $processor->processPayload('{ union(type: "asd") { ... on Object2 { name } } }');
515
        $this->assertEquals(['data' => ['union' => ['name' => 'name resolved']]], $processor->getResponseData());
516
517
        $processor->processPayload('{ invalidUnion { ... on Object2 { name } } }');
518
        $this->assertEquals(['errors' => [['message' => 'Type Object3 not exist in types of Object2']]], $processor->getResponseData());
519
520
        $visitor = new MaxComplexityQueryVisitor(1000); // arbitrarily high cost
521
        $processor->processPayload('{ union(type: "object1") { ... on Object1 { id } } }', [], [$visitor]);
522
        $this->assertEquals(10 + 13, $visitor->getMemo());
523
524
        $visitor = new MaxComplexityQueryVisitor(1000); // arbitrarily high cost
525
        $processor->processPayload('{ union(type: "object1") { ... on Object1 { id }, ... on Object2 { name } } }', [], [$visitor]);
526
        $this->assertEquals(10 + 13 + 1, $visitor->getMemo());
527
528
        // planning phase currently has no knowledge of what types the union will resolve to, this will have the same score as above
529
        $visitor = new MaxComplexityQueryVisitor(1000); // arbitrarily high cost
530
        $processor->processPayload('{ union(type: "object2") { ... on Object1 { id }, ... on Object2 { name } } }', [], [$visitor]);
531
        $this->assertEquals(10 + 13 + 1, $visitor->getMemo());
532
    }
533
534
    public function testComplexityReducer()
535
    {
536
        $schema    = new Schema(
537
            [
538
                'query' => new ObjectType(
539
                    [
540
                        'name'   => 'RootQuery',
541
                        'fields' => [
542
                            'me' => [
543
                                'type'    => new ObjectType(
544
                                    [
545
                                        'name'   => 'User',
546
                                        'fields' => [
547
                                            'firstName' => [
548
                                                'type'    => new StringType(),
549
                                                'args'    => [
550
                                                    'shorten' => new BooleanType()
551
                                                ],
552
                                                'resolve' => function ($value, $args) {
553
                                                    return empty($args['shorten']) ? $value : $value;
554
                                                }
555
                                            ],
556
                                            'lastName'  => new StringType(),
557
                                            'code'      => new StringType(),
558
                                            'likes'     => [
559
                                                'type'    => new IntType(),
560
                                                'cost'    => 10,
561
                                                'resolve' => function () {
562
                                                    return 42;
563
                                                }
564
                                            ]
565
                                        ]
566
                                    ]
567
                                ),
568
                                'cost'    => function ($args, $context, $childCost) {
569
                                    $argsCost = isset($args['cost']) ? $args['cost'] : 1;
570
571
                                    return 1 + $argsCost * $childCost;
572
                                },
573
                                'resolve' => function ($value, $args) {
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
574
                                    $data = ['firstName' => 'John', 'code' => '007'];
575
576
                                    return $data;
577
                                },
578
                                'args'    => [
579
                                    'cost' => [
580
                                        'type'    => new IntType(),
581
                                        'default' => 1
582
                                    ]
583
                                ]
584
                            ]
585
                        ]
586
                    ]
587
                )
588
            ]
589
        );
590
        $processor = new Processor($schema);
591
592
        $processor->setMaxComplexity(10);
593
594
        $processor->processPayload('{ me { firstName, lastName } }');
595
        $this->assertArrayNotHasKey('error', $processor->getResponseData());
596
597
        $processor->processPayload('{ me { firstName, likes } }');
598
        $this->assertEquals(['errors' => [['message' => 'query exceeded max allowed complexity of 10']]], $processor->getResponseData());
599
600
        // don't let complexity reducer affect query errors
601
        $processor->processPayload('{ me { badfield } }');
602
        $this->assertArraySubset(['errors' => [['message' => 'Field "badfield" is not found in type "User"']]], $processor->getResponseData());
603
604
        foreach (range(1, 5) as $cost_multiplier) {
605
            $visitor = new MaxComplexityQueryVisitor(1000); // arbitrarily high cost
606
            $processor->processPayload("{ me (cost: $cost_multiplier) { firstName, lastName, code, likes } }", ['cost' => $cost_multiplier], [$visitor]);
607
            $expected = 1 + 13 * (1 + $cost_multiplier);
608
            $this->assertEquals($expected, $visitor->getMemo());
609
        }
610
611
        // TODO, variables not yet supported
612
        /*$query = 'query costQuery ($cost: Int) { me (cost: $cost) { firstName, lastName, code, likes } }';
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
613
        foreach (range(1,5) as $cost_multiplier) {
614
          $visitor = new \Youshido\GraphQL\Execution\Visitor\MaxComplexityQueryVisitor(1000); // arbitrarily high cost
615
          $processor->processPayload($query, ['cost' => $cost_multiplier], [$visitor]);
616
          $expected = 1 + 13 * (1 + $cost_multiplier);
617
          $this->assertEquals($expected, $visitor->getMemo());
618
        }*/
619
    }
620
}
621