|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the OverblogGraphQLPhpGenerator package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Overblog <http://github.com/overblog/> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Overblog\GraphQLGenerator\Tests; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class StarWarsData |
|
16
|
|
|
* |
|
17
|
|
|
* This is a copy of original test file GraphQL\Tests\StarWarsData |
|
18
|
|
|
* |
|
19
|
|
|
*/ |
|
20
|
|
|
class StarWarsData |
|
21
|
|
|
{ |
|
22
|
|
|
private static function luke() |
|
23
|
|
|
{ |
|
24
|
|
|
return [ |
|
25
|
|
|
'id' => '1000', |
|
26
|
|
|
'name' => 'Luke Skywalker', |
|
27
|
|
|
'friends' => ['1002', '1003', '2000', '2001'], |
|
28
|
|
|
'appearsIn' => [4, 5, 6], |
|
29
|
|
|
'homePlanet' => 'Tatooine', |
|
30
|
|
|
]; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
private static function vader() |
|
34
|
|
|
{ |
|
35
|
|
|
return [ |
|
36
|
|
|
'id' => '1001', |
|
37
|
|
|
'name' => 'Darth Vader', |
|
38
|
|
|
'friends' => ['1004'], |
|
39
|
|
|
'appearsIn' => [4, 5, 6], |
|
40
|
|
|
'homePlanet' => 'Tatooine', |
|
41
|
|
|
]; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
private static function han() |
|
45
|
|
|
{ |
|
46
|
|
|
return [ |
|
47
|
|
|
'id' => '1002', |
|
48
|
|
|
'name' => 'Han Solo', |
|
49
|
|
|
'friends' => ['1000', '1003', '2001'], |
|
50
|
|
|
'appearsIn' => [4, 5, 6], |
|
51
|
|
|
]; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
private static function leia() |
|
55
|
|
|
{ |
|
56
|
|
|
return [ |
|
57
|
|
|
'id' => '1003', |
|
58
|
|
|
'name' => 'Leia Organa', |
|
59
|
|
|
'friends' => ['1000', '1002', '2000', '2001'], |
|
60
|
|
|
'appearsIn' => [4, 5, 6], |
|
61
|
|
|
'homePlanet' => 'Alderaan', |
|
62
|
|
|
]; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
private static function tarkin() |
|
66
|
|
|
{ |
|
67
|
|
|
return [ |
|
68
|
|
|
'id' => '1004', |
|
69
|
|
|
'name' => 'Wilhuff Tarkin', |
|
70
|
|
|
'friends' => ['1001'], |
|
71
|
|
|
'appearsIn' => [4], |
|
72
|
|
|
]; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public static function humans() |
|
76
|
|
|
{ |
|
77
|
|
|
return [ |
|
78
|
|
|
'1000' => self::luke(), |
|
79
|
|
|
'1001' => self::vader(), |
|
80
|
|
|
'1002' => self::han(), |
|
81
|
|
|
'1003' => self::leia(), |
|
82
|
|
|
'1004' => self::tarkin(), |
|
83
|
|
|
]; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
private static function threepio() |
|
87
|
|
|
{ |
|
88
|
|
|
return [ |
|
89
|
|
|
'id' => '2000', |
|
90
|
|
|
'name' => 'C-3PO', |
|
91
|
|
|
'friends' => ['1000', '1002', '1003', '2001'], |
|
92
|
|
|
'appearsIn' => [4, 5, 6], |
|
93
|
|
|
'primaryFunction' => 'Protocol', |
|
94
|
|
|
]; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* We export artoo directly because the schema returns him |
|
99
|
|
|
* from a root field, and hence needs to reference him. |
|
100
|
|
|
*/ |
|
101
|
|
|
public static function artoo() |
|
102
|
|
|
{ |
|
103
|
|
|
return [ |
|
104
|
|
|
|
|
105
|
|
|
'id' => '2001', |
|
106
|
|
|
'name' => 'R2-D2', |
|
107
|
|
|
'friends' => ['1000', '1002', '1003'], |
|
108
|
|
|
'appearsIn' => [4, 5, 6], |
|
109
|
|
|
'primaryFunction' => 'Astromech', |
|
110
|
|
|
]; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public static function droids() |
|
114
|
|
|
{ |
|
115
|
|
|
return [ |
|
116
|
|
|
'2000' => self::threepio(), |
|
117
|
|
|
'2001' => self::artoo(), |
|
118
|
|
|
]; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Helper function to get a character by ID. |
|
123
|
|
|
*/ |
|
124
|
|
|
public static function getCharacter($id) |
|
125
|
|
|
{ |
|
126
|
|
|
$humans = self::humans(); |
|
127
|
|
|
$droids = self::droids(); |
|
128
|
|
|
if (isset($humans[$id])) { |
|
129
|
|
|
return $humans[$id]; |
|
130
|
|
|
} |
|
131
|
|
|
if (isset($droids[$id])) { |
|
132
|
|
|
return $droids[$id]; |
|
133
|
|
|
} |
|
134
|
|
|
return null; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Allows us to query for a character's friends. |
|
139
|
|
|
*/ |
|
140
|
|
|
public static function getFriends($character) |
|
141
|
|
|
{ |
|
142
|
|
|
return \array_map([__CLASS__, 'getCharacter'], $character['friends']); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @param $episode |
|
147
|
|
|
* @return array |
|
148
|
|
|
*/ |
|
149
|
|
|
public static function getHero($episode) |
|
150
|
|
|
{ |
|
151
|
|
|
if ($episode === 5) { |
|
152
|
|
|
// Luke is the hero of Episode V. |
|
153
|
|
|
return self::luke(); |
|
154
|
|
|
} |
|
155
|
|
|
// Artoo is the hero otherwise. |
|
156
|
|
|
return self::artoo(); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @param $id |
|
161
|
|
|
* @return mixed|null |
|
162
|
|
|
*/ |
|
163
|
|
|
public static function getHuman($id) |
|
164
|
|
|
{ |
|
165
|
|
|
$humans = self::humans(); |
|
166
|
|
|
return isset($humans[$id]) ? $humans[$id] : null; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @param $id |
|
171
|
|
|
* @return mixed|null |
|
172
|
|
|
*/ |
|
173
|
|
|
public static function getDroid($id) |
|
174
|
|
|
{ |
|
175
|
|
|
$droids = self::droids(); |
|
176
|
|
|
return isset($droids[$id]) ? $droids[$id] : null; |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|