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