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\Processor; |
12
|
|
|
use Youshido\GraphQL\Validator\ResolveValidator\ResolveValidator; |
13
|
|
|
use Youshido\Tests\StarWars\Schema\Schema; |
14
|
|
|
|
15
|
|
|
class StarWarsTest extends \PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param $query |
20
|
|
|
* @param $validResult |
21
|
|
|
* @param $variables |
22
|
|
|
* |
23
|
|
|
* @dataProvider dataProvider |
24
|
|
|
*/ |
25
|
|
View Code Duplication |
public function testSchema($query, $validResult, $variables) |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$processor = new Processor(new ResolveValidator()); |
28
|
|
|
$processor->setSchema(new Schema()); |
29
|
|
|
|
30
|
|
|
$processor->processQuery($query, $variables); |
31
|
|
|
|
32
|
|
|
$this->assertEquals($processor->getResponseData(), $validResult); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
public function dataProvider() |
37
|
|
|
{ |
38
|
|
|
return [ |
39
|
|
|
[ |
40
|
|
|
'query CheckTypeOfLuke { |
41
|
|
|
hero(episode: EMPIRE) { |
42
|
|
|
__typename, |
43
|
|
|
name |
44
|
|
|
} |
45
|
|
|
}', |
46
|
|
|
[ |
47
|
|
|
'data' => [ |
48
|
|
|
'hero' => [ |
49
|
|
|
'__typename' => 'Human', |
50
|
|
|
'name' => 'Luke Skywalker' |
51
|
|
|
], |
52
|
|
|
] |
53
|
|
|
], |
54
|
|
|
[] |
55
|
|
|
], |
56
|
|
|
[ |
57
|
|
|
'query { |
58
|
|
|
hero { |
59
|
|
|
name |
60
|
|
|
} |
61
|
|
|
}', |
62
|
|
|
['data' => [ |
63
|
|
|
'hero' => [ |
64
|
|
|
'name' => 'R2-D2' |
65
|
|
|
] |
66
|
|
|
]], |
67
|
|
|
[] |
68
|
|
|
], |
69
|
|
|
[ |
70
|
|
|
'query { |
71
|
|
|
hero { |
72
|
|
|
id, |
73
|
|
|
name, |
74
|
|
|
friends { |
75
|
|
|
name |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
}', |
79
|
|
|
['data' => [ |
80
|
|
|
'hero' => [ |
81
|
|
|
'id' => '2001', |
82
|
|
|
'name' => 'R2-D2', |
83
|
|
|
'friends' => [ |
84
|
|
|
[ |
85
|
|
|
'name' => 'Luke Skywalker', |
86
|
|
|
], |
87
|
|
|
[ |
88
|
|
|
'name' => 'Han Solo', |
89
|
|
|
], |
90
|
|
|
[ |
91
|
|
|
'name' => 'Leia Organa', |
92
|
|
|
], |
93
|
|
|
] |
94
|
|
|
] |
95
|
|
|
]], |
96
|
|
|
[] |
97
|
|
|
], |
98
|
|
|
[ |
99
|
|
|
'{ |
100
|
|
|
hero { |
101
|
|
|
name, |
102
|
|
|
friends { |
103
|
|
|
name, |
104
|
|
|
appearsIn, |
105
|
|
|
friends { |
106
|
|
|
name |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
}', |
111
|
|
|
[ |
112
|
|
|
'data' => [ |
113
|
|
|
'hero' => [ |
114
|
|
|
'name' => 'R2-D2', |
115
|
|
|
'friends' => [ |
116
|
|
|
[ |
117
|
|
|
'name' => 'Luke Skywalker', |
118
|
|
|
'appearsIn' => ['NEWHOPE', 'EMPIRE', 'JEDI',], |
119
|
|
|
'friends' => [ |
120
|
|
|
['name' => 'Han Solo',], |
121
|
|
|
['name' => 'Leia Organa',], |
122
|
|
|
['name' => 'C-3PO',], |
123
|
|
|
['name' => 'R2-D2',], |
124
|
|
|
], |
125
|
|
|
], |
126
|
|
|
[ |
127
|
|
|
'name' => 'Han Solo', |
128
|
|
|
'appearsIn' => ['NEWHOPE', 'EMPIRE', 'JEDI'], |
129
|
|
|
'friends' => [ |
130
|
|
|
['name' => 'Luke Skywalker',], |
131
|
|
|
['name' => 'Leia Organa'], |
132
|
|
|
['name' => 'R2-D2',], |
133
|
|
|
] |
134
|
|
|
], |
135
|
|
|
[ |
136
|
|
|
'name' => 'Leia Organa', |
137
|
|
|
'appearsIn' => ['NEWHOPE', 'EMPIRE', 'JEDI'], |
138
|
|
|
'friends' => |
139
|
|
|
[ |
140
|
|
|
['name' => 'Luke Skywalker',], |
141
|
|
|
['name' => 'Han Solo',], |
142
|
|
|
['name' => 'C-3PO',], |
143
|
|
|
['name' => 'R2-D2',], |
144
|
|
|
], |
145
|
|
|
], |
146
|
|
|
], |
147
|
|
|
] |
148
|
|
|
] |
149
|
|
|
], |
150
|
|
|
[] |
151
|
|
|
], |
152
|
|
|
[ |
153
|
|
|
'{ |
154
|
|
|
human(id: "1000") { |
155
|
|
|
name |
156
|
|
|
} |
157
|
|
|
}', |
158
|
|
|
[ |
159
|
|
|
'data' => [ |
160
|
|
|
'human' => [ |
161
|
|
|
'name' => 'Luke Skywalker' |
162
|
|
|
] |
163
|
|
|
] |
164
|
|
|
], |
165
|
|
|
[] |
166
|
|
|
], |
167
|
|
|
[ |
168
|
|
|
'{ |
169
|
|
|
human(id: $someId) { |
170
|
|
|
name |
171
|
|
|
} |
172
|
|
|
}', |
173
|
|
|
[ |
174
|
|
|
'data' => [ |
175
|
|
|
'human' => [ |
176
|
|
|
'name' => 'Luke Skywalker' |
177
|
|
|
] |
178
|
|
|
] |
179
|
|
|
], |
180
|
|
|
[ |
181
|
|
|
'someId' => '1000' |
182
|
|
|
] |
183
|
|
|
] |
184
|
|
|
]; |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.