Completed
Push — master ( e13501...8c19ea )
by Alexandr
05:24
created

RequestValidatorTest::invalidRequestProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 89
Code Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 89
rs 8.5731
c 0
b 0
f 0
cc 1
eloc 50
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
 * Date: 27.10.16
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\Tests\Library\Validator;
9
10
11
use Youshido\GraphQL\Execution\Request;
12
use Youshido\GraphQL\Parser\Ast\Argument;
13
use Youshido\GraphQL\Parser\Ast\ArgumentValue\Variable;
14
use Youshido\GraphQL\Parser\Ast\ArgumentValue\VariableReference;
15
use Youshido\GraphQL\Parser\Ast\Field;
16
use Youshido\GraphQL\Parser\Ast\Fragment;
17
use Youshido\GraphQL\Parser\Ast\FragmentReference;
18
use Youshido\GraphQL\Parser\Ast\Query;
19
use Youshido\GraphQL\Validator\RequestValidator\RequestValidator;
20
21
class RequestValidatorTest extends \PHPUnit_Framework_TestCase
22
{
23
24
    /**
25
     * @expectedException Youshido\GraphQL\Parser\Exception\InvalidRequestException
26
     * @dataProvider invalidRequestProvider
27
     *
28
     * @param Request $request
29
     */
30
    public function testInvalidRequests(Request $request)
31
    {
32
        (new RequestValidator())->validate($request);
33
    }
34
35
    public function invalidRequestProvider()
36
    {
37
        $variable1 = (new Variable('test', 'Int'))->setUsed(true);
38
        $variable2 = (new Variable('test2', 'Int'))->setUsed(true);
39
        $variable3 = (new Variable('test3', 'Int'))->setUsed(false);
40
41
        return [
42
            [
43
                new Request([
44
                    'queries'            => [
45
                        new Query('test', null, [], [
46
                            new FragmentReference('reference')
47
                        ])
48
                    ],
49
                    'fragmentReferences' => [
50
                        new FragmentReference('reference')
51
                    ]
52
                ])
53
            ],
54
            [
55
                new Request([
56
                    'queries'            => [
57
                        new Query('test', null, [], [
58
                            new FragmentReference('reference'),
59
                            new FragmentReference('reference2'),
60
                        ])
61
                    ],
62
                    'fragments'          => [
63
                        new Fragment('reference', 'TestType', [])
64
                    ],
65
                    'fragmentReferences' => [
66
                        new FragmentReference('reference'),
67
                        new FragmentReference('reference2')
68
                    ]
69
                ])
70
            ],
71
            [
72
                new Request([
73
                    'queries'            => [
74
                        new Query('test', null, [], [
75
                            new FragmentReference('reference'),
76
                        ])
77
                    ],
78
                    'fragments'          => [
79
                        new Fragment('reference', 'TestType', []),
80
                        new Fragment('reference2', 'TestType', [])
81
                    ],
82
                    'fragmentReferences' => [
83
                        new FragmentReference('reference')
84
                    ]
85
                ])
86
            ],
87
            [
88
                new Request([
89
                    'queries'            => [
90
                        new Query('test', null, [
91
                            new Argument('test', new VariableReference('test'))
92
                        ], [
93
                            new Field('test')
94
                        ])
95
                    ],
96
                    'variableReferences' => [
97
                        new VariableReference('test')
98
                    ]
99
                ])
100
            ],
101
            [
102
                new Request([
103
                    'queries'            => [
104
                        new Query('test', null, [
105
                            new Argument('test', new VariableReference('test', $variable1)),
106
                            new Argument('test2', new VariableReference('test2', $variable2)),
107
                        ], [
108
                            new Field('test')
109
                        ])
110
                    ],
111
                    'variables'          => [
112
                        $variable1,
113
                        $variable2,
114
                        $variable3
115
                    ],
116
                    'variableReferences' => [
117
                        new VariableReference('test', $variable1),
118
                        new VariableReference('test2', $variable2)
119
                    ]
120
                ])
121
            ]
122
        ];
123
    }
124
125
}