Completed
Pull Request — master (#160)
by
unknown
02:48
created

StarWarsTest::dataProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 150
Code Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 150
rs 8.2857
cc 1
eloc 54
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: 07.12.15
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\Tests\StarWars;
9
10
11
use Youshido\GraphQL\Execution\Processor;
12
use Youshido\Tests\StarWars\Schema\StarWarsSchema;
13
14
class StarWarsTest extends \PHPUnit_Framework_TestCase
15
{
16
17
    /**
18
     * @param $query
19
     * @param $validResult
20
     * @param $variables
21
     *
22
     * @dataProvider dataProvider
23
     */
24
    public function testSchema($query, $validResult, $variables)
25
    {
26
        $processor = new Processor(new StarWarsSchema());
27
28
        $processor->processPayload($query, $variables);
29
30
        $responseData = $processor->getResponseData();
31
        $this->assertEquals($validResult, $responseData);
32
    }
33
34
    public function testInvalidVariableType()
35
    {
36
        $processor = new Processor(new StarWarsSchema());
37
38
        $processor->processPayload(
39
            'query($someId: Int){
40
                human(id: $someId) {
41
                    name
42
                }
43
            }', ['someId' => 1]
44
        );
45
46
        $data = $processor->getResponseData();
47
        $this->assertEquals($data, [
48
            'data'   => ['human' => null],
49
            'errors' => [
50
                [
51
                    'message'   => 'Invalid variable "someId" type, allowed type is "ID"',
52
                    'locations' => [
53
                        [
54
                            'line'   => 1,
55
                            'column' => 7
56
                        ]
57
                    ]
58
                ]
59
            ]
60
        ]);
61
    }    
62
	
63
	public function testMultipleRootFields()
64
    {
65
        $processor = new Processor(new StarWarsSchema());
66
67
        $processor->processPayload(
68
            'query(){
69
                q1: human(id: "1000") {
70
                    name
71
                }
72
                q2: human(id: "1001") {
73
                    name
74
                }
75
            }', []
76
        );
77
78
        $data = $processor->getResponseData();
79
        $this->assertEquals($data, [
80
            'data'   => [
81
				'q1' => ['name' => 'Luke Skywalker'],
82
				'q2' => ['name' => 'Darth Vader'],
83
			],
84
        ]);
85
    }
86
87
88
    public function dataProvider()
89
    {
90
        return [
91
            [
92
                'query CheckTypeOfLuke {
93
                  hero(episode: EMPIRE) {
94
                    __typename,
95
                    name
96
                  }
97
                }',
98
                [
99
                    'data' => [
100
                        'hero' => [
101
                            '__typename' => 'Human',
102
                            'name'       => 'Luke Skywalker'
103
                        ],
104
                    ]
105
                ],
106
                []
107
            ],
108
            [
109
                'query {
110
                  hero {
111
                    name
112
                  }
113
              }',
114
                ['data' => [
115
                    'hero' => [
116
                        'name' => 'R2-D2'
117
                    ]
118
                ]],
119
                []
120
            ],
121
            [
122
                'query {
123
                  hero {
124
                    id,
125
                    name,
126
                    friends {
127
                      name
128
                    }
129
                  }
130
                }',
131
                ['data' => [
132
                    'hero' => [
133
                        'id'      => '2001',
134
                        'name'    => 'R2-D2',
135
                        'friends' => [
136
                            [
137
                                'name' => 'Luke Skywalker',
138
                            ],
139
                            [
140
                                'name' => 'Han Solo',
141
                            ],
142
                            [
143
                                'name' => 'Leia Organa',
144
                            ],
145
                        ]
146
                    ]
147
                ]],
148
                []
149
            ],
150
            [
151
                '{
152
                  hero {
153
                    name,
154
                    friends {
155
                      name,
156
                      appearsIn,
157
                      friends {
158
                        name
159
                      }
160
                    }
161
                  }
162
                }',
163
                [
164
                    'data' => [
165
                        'hero' => [
166
                            'name'    => 'R2-D2',
167
                            'friends' => [
168
                                [
169
                                    'name'      => 'Luke Skywalker',
170
                                    'appearsIn' => ['NEWHOPE', 'EMPIRE', 'JEDI',],
171
                                    'friends'   => [
172
                                        ['name' => 'Han Solo',],
173
                                        ['name' => 'Leia Organa',],
174
                                        ['name' => 'C-3PO',],
175
                                        ['name' => 'R2-D2',],
176
                                    ],
177
                                ],
178
                                [
179
                                    'name'      => 'Han Solo',
180
                                    'appearsIn' => ['NEWHOPE', 'EMPIRE', 'JEDI'],
181
                                    'friends'   => [
182
                                        ['name' => 'Luke Skywalker',],
183
                                        ['name' => 'Leia Organa'],
184
                                        ['name' => 'R2-D2',],
185
                                    ]
186
                                ],
187
                                [
188
                                    'name'      => 'Leia Organa',
189
                                    'appearsIn' => ['NEWHOPE', 'EMPIRE', 'JEDI'],
190
                                    'friends'   =>
191
                                        [
192
                                            ['name' => 'Luke Skywalker',],
193
                                            ['name' => 'Han Solo',],
194
                                            ['name' => 'C-3PO',],
195
                                            ['name' => 'R2-D2',],
196
                                        ],
197
                                ],
198
                            ],
199
                        ]
200
                    ]
201
                ],
202
                []
203
            ],
204
            [
205
                '{
206
                  human(id: "1000") {
207
                    name
208
                  }
209
                }',
210
                [
211
                    'data' => [
212
                        'human' => [
213
                            'name' => 'Luke Skywalker'
214
                        ]
215
                    ]
216
                ],
217
                []
218
            ],
219
            [
220
                'query($someId: ID){
221
                  human(id: $someId) {
222
                    name
223
                  }
224
                }',
225
                [
226
                    'data' => [
227
                        'human' => [
228
                            'name' => 'Luke Skywalker'
229
                        ]
230
                    ]
231
                ],
232
                [
233
                    'someId' => '1000'
234
                ]
235
            ]
236
        ];
237
    }
238
}
239