Failed Conditions
Push — master ( 48b44f...392b56 )
by Vladimir
04:42
created

ServerTestCase   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 52
dl 0
loc 81
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A buildSchema() 0 79 1
1
<?php
2
namespace GraphQL\Tests\Server;
3
4
5
use GraphQL\Deferred;
6
use GraphQL\Error\UserError;
7
use GraphQL\Type\Definition\ObjectType;
8
use GraphQL\Type\Definition\Type;
9
use GraphQL\Type\Schema;
10
use PHPUnit\Framework\TestCase;
11
12
abstract class ServerTestCase extends TestCase
13
{
14
    protected function buildSchema()
15
    {
16
        $schema = new Schema([
17
            'query' => new ObjectType([
18
                'name' => 'Query',
19
                'fields' => [
20
                    'f1' => [
21
                        'type' => Type::string(),
22
                        'resolve' => function($root, $args, $context, $info) {
23
                            return $info->fieldName;
24
                        }
25
                    ],
26
                    'fieldWithPhpError' => [
27
                        'type' => Type::string(),
28
                        'resolve' => function($root, $args, $context, $info) {
29
                            trigger_error('deprecated', E_USER_DEPRECATED);
30
                            trigger_error('notice', E_USER_NOTICE);
31
                            trigger_error('warning', E_USER_WARNING);
32
                            $a = [];
33
                            $a['test']; // should produce PHP notice
34
                            return $info->fieldName;
35
                        }
36
                    ],
37
                    'fieldWithException' => [
38
                        'type' => Type::string(),
39
                        'resolve' => function($root, $args, $context, $info) {
0 ignored issues
show
Unused Code introduced by
The parameter $root is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

39
                        'resolve' => function(/** @scrutinizer ignore-unused */ $root, $args, $context, $info) {

This check looks for 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. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

39
                        'resolve' => function($root, /** @scrutinizer ignore-unused */ $args, $context, $info) {

This check looks for 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 $context is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

39
                        'resolve' => function($root, $args, /** @scrutinizer ignore-unused */ $context, $info) {

This check looks for 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 $info is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

39
                        'resolve' => function($root, $args, $context, /** @scrutinizer ignore-unused */ $info) {

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

Loading history...
40
                            throw new UserError("This is the exception we want");
41
                        }
42
                    ],
43
                    'testContextAndRootValue' => [
44
                        'type' => Type::string(),
45
                        'resolve' => function($root, $args, $context, $info) {
46
                            $context->testedRootValue = $root;
47
                            return $info->fieldName;
48
                        }
49
                    ],
50
                    'fieldWithArg' => [
51
                        'type' => Type::string(),
52
                        'args' => [
53
                            'arg' => [
54
                                'type' => Type::nonNull(Type::string())
55
                            ],
56
                        ],
57
                        'resolve' => function($root, $args) {
58
                            return $args['arg'];
59
                        }
60
                    ],
61
                    'dfd' => [
62
                        'type' => Type::string(),
63
                        'args' => [
64
                            'num' => [
65
                                'type' => Type::nonNull(Type::int())
66
                            ],
67
                        ],
68
                        'resolve' => function($root, $args, $context) {
69
                            $context['buffer']($args['num']);
70
71
                            return new Deferred(function() use ($args, $context) {
72
                                return $context['load']($args['num']);
73
                            });
74
                        }
75
                    ]
76
                ]
77
            ]),
78
            'mutation' => new ObjectType([
79
                'name' => 'Mutation',
80
                'fields' => [
81
                    'm1' => [
82
                        'type' => new ObjectType([
83
                            'name' => 'TestMutation',
84
                            'fields' => [
85
                                'result' => Type::string()
86
                            ]
87
                        ])
88
                    ]
89
                ]
90
            ])
91
        ]);
92
        return $schema;
93
    }
94
}
95