Completed
Push — master ( 331d29...e40fed )
by Portey
02:57
created

ParserTest::mutationProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 68
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 2 Features 2
Metric Value
c 5
b 2
f 2
dl 0
loc 68
rs 9.2448
cc 1
eloc 32
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: 01.12.15
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\tests\GraphQL\Parser;
9
10
use Youshido\GraphQL\Parser\Ast\Argument;
11
use Youshido\GraphQL\Parser\Ast\Field;
12
use Youshido\GraphQL\Parser\Ast\Mutation;
13
use Youshido\GraphQL\Parser\Value\InputList;
14
use Youshido\GraphQL\Parser\Value\InputObject;
15
use Youshido\GraphQL\Parser\Value\Literal;
16
use Youshido\GraphQL\Parser\Ast\Query;
17
use Youshido\GraphQL\Parser\Parser;
18
use Youshido\GraphQL\Parser\Value\Variable;
19
20
class ParserTest extends \PHPUnit_Framework_TestCase
21
{
22
23
    /**
24
     * @dataProvider mutationProvider
25
     */
26
    public function testMutations($query, $structure)
27
    {
28
        $parser = new Parser();
29
        $parser->setSource($query);
30
31
        $parsedStructure = $parser->parse();
32
33
        $this->assertEquals($parsedStructure, $structure);
34
    }
35
36
    public function mutationProvider()
37
    {
38
        return [
39
            [
40
                '{ query ( teas: $variable ) { alias: name } }',
41
                [
42
                    'queries' => [
43
                        new Query('query', null,
44
                            [
45
                                new Argument('teas', new Variable('variable'))
46
                            ],
47
                            [
48
                                new Field('name', 'alias')
49
                            ])
50
                    ],
51
                    'mutations' => [],
52
                    'fragments' => []
53
                ]
54
            ],
55
            [
56
                '{ query { alias: name } }',
57
                [
58
                    'queries' => [
59
                        new Query('query', null, [], [new Field('name', 'alias')])
60
                    ],
61
                    'mutations' => [],
62
                    'fragments' => []
63
                ]
64
            ],
65
            [
66
                'mutation { createUser ( email: "[email protected]", active: true ) { id } }',
67
                [
68
                    'queries'   => [],
69
                    'mutations' => [
70
                        new Mutation(
71
                            'createUser',
72
                            null,
73
                            [
74
                                new Argument('email', new Literal('[email protected]')),
75
                                new Argument('active', new Literal(true)),
76
                            ],
77
                            [
78
                                new Field('id')
79
                            ]
80
                        )
81
                    ],
82
                    'fragments' => []
83
                ]
84
            ],
85
            [
86
                'mutation { test : createUser (id: 4) }',
87
                [
88
                    'queries'   => [],
89
                    'mutations' => [
90
                        new Mutation(
91
                            'createUser',
92
                            'test',
93
                            [
94
                                new Argument('id', new Literal(4)),
95
                            ],
96
                            []
97
                        )
98
                    ],
99
                    'fragments' => []
100
                ]
101
            ]
102
        ];
103
    }
104
105
    /**
106
     * @dataProvider queryProvider
107
     */
108
    public function testParser($query, $structure)
109
    {
110
        $parser = new Parser();
111
        $parser->setSource($query);
112
113
        $parsedStructure = $parser->parse();
114
115
        $this->assertEquals($parsedStructure, $structure);
116
    }
117
118
119
    public function queryProvider()
120
    {
121
        return [
122
            [
123
                '{}',
124
                [
125
                    'queries'   => [],
126
                    'mutations' => [],
127
                    'fragments' => []
128
                ]
129
            ],
130
            [
131
                '{ user (id: 10, name: "max", float: 123.123 ) { id, name } }',
132
                [
133
                    'queries'   => [
134
                        new Query(
135
                            'user',
136
                            null,
137
                            [
138
                                new Argument('id', new Literal('10')),
139
                                new Argument('name', new Literal('max')),
140
                                new Argument('float', new Literal('123.123'))
141
                            ],
142
                            [
143
                                new Field('id'),
144
                                new Field('name')
145
                            ]
146
                        )
147
                    ],
148
                    'mutations' => [],
149
                    'fragments' => []
150
                ]
151
            ],
152
            [
153
                '{ allUsers : users ( id: [ 1, 2, 3] ) { id } }',
154
                [
155
                    'queries'   => [
156
                        new Query(
157
                            'users',
158
                            'allUsers',
159
                            [
160
                                new Argument('id', new InputList([1, 2, 3]))
161
                            ],
162
                            [
163
                                new Field('id')
164
                            ]
165
                        )
166
                    ],
167
                    'mutations' => [],
168
                    'fragments' => []
169
                ]
170
            ],
171
            [
172
                '{ allUsers : users ( id: [ 1, "2", true, null] ) { id } }',
173
                [
174
                    'queries'   => [
175
                        new Query(
176
                            'users',
177
                            'allUsers',
178
                            [
179
                                new Argument('id', new InputList([1, "2", true, null]))
180
                            ],
181
                            [
182
                                new Field('id')
183
                            ]
184
                        )
185
                    ],
186
                    'mutations' => [],
187
                    'fragments' => []
188
                ]
189
            ],
190
            [
191
                '{ allUsers : users ( object: { "a": 123, "d": "asd",  "b" : [ 1, 2, 4 ], "c": { "a" : 123, "b":  "asd" } } ) { id } }',
192
                [
193
                    'queries'   => [
194
                        new Query(
195
                            'users',
196
                            'allUsers',
197
                            [
198
                                new Argument('object', new InputObject([
199
                                    'a' => 123,
200
                                    'd' => 'asd',
201
                                    'b' => [1, 2, 4],
202
                                    'c' => [
203
                                        'a' => 123,
204
                                        'b' => 'asd'
205
                                    ]
206
                                ]))
207
                            ],
208
                            [
209
                                new Field('id')
210
                            ]
211
                        )
212
                    ],
213
                    'mutations' => [],
214
                    'fragments' => []
215
                ]
216
            ]
217
        ];
218
    }
219
220
}