|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is a part of GraphQL project. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Alexandr Viniychuk <[email protected]> |
|
6
|
|
|
* created: 5/10/16 11:07 PM |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Examples\StarWars; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class TestDataProvider |
|
13
|
|
|
{ |
|
14
|
|
|
private static $ships = [ |
|
15
|
|
|
'xwing' => ['id' => 1, 'name' => 'X-Wing'], |
|
16
|
|
|
'ywing' => ['id' => 2, 'name' => 'Y-Wing'], |
|
17
|
|
|
'awing' => ['id' => 3, 'name' => 'A-Wing'], |
|
18
|
|
|
|
|
19
|
|
|
'falcon' => ['id' => 4, 'name' => 'Millenium Falcon'], |
|
20
|
|
|
'homeOne' => ['id' => 5, 'name' => 'Home One'], |
|
21
|
|
|
'tieFighter' => ['id' => 6, 'name' => 'TIE Fighter'], |
|
22
|
|
|
'tieInterceptor' => ['id' => 7, 'name' => 'TIE Interceptor'], |
|
23
|
|
|
'executor' => ['id' => 8, 'name' => 'Executor'], |
|
24
|
|
|
]; |
|
25
|
|
|
|
|
26
|
|
|
private static $factions = [ |
|
27
|
|
|
'1' => [ |
|
28
|
|
|
'id' => 1, |
|
29
|
|
|
'name' => 'Alliance to Restore the Republic', |
|
30
|
|
|
'ships' => [1, 2, 3, 4, 5] |
|
31
|
|
|
], |
|
32
|
|
|
'2' => [ |
|
33
|
|
|
'id' => 2, |
|
34
|
|
|
'name' => 'Galactic Empire', |
|
35
|
|
|
'ships' => [6, 7, 8] |
|
36
|
|
|
], |
|
37
|
|
|
]; |
|
38
|
|
|
|
|
39
|
|
|
private static $nextShipId = 9; |
|
40
|
|
|
|
|
41
|
|
|
public static function getByNames($names) |
|
42
|
|
|
{ |
|
43
|
|
|
$result = []; |
|
44
|
|
|
|
|
45
|
|
|
foreach($names as $name) { |
|
46
|
|
|
if ($name == 'rebels') { |
|
47
|
|
|
$result[] = self::$factions[1]; |
|
48
|
|
|
} elseif($name == 'empire') { |
|
49
|
|
|
$result[] = self::$factions[2]; |
|
50
|
|
|
} else { |
|
51
|
|
|
$result[] = null; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return $result; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public static function createShip($name, $factionId) |
|
59
|
|
|
{ |
|
60
|
|
|
$newShip = [ |
|
61
|
|
|
'id' => self::$nextShipId++, |
|
62
|
|
|
'name' => $name |
|
63
|
|
|
]; |
|
64
|
|
|
|
|
65
|
|
|
self::$ships[$newShip['id']] = $newShip; |
|
66
|
|
|
self::$factions[$factionId]['ships'][] = $newShip['id']; |
|
67
|
|
|
|
|
68
|
|
|
return $newShip; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public static function getFactions() |
|
72
|
|
|
{ |
|
73
|
|
|
return self::$factions; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public static function getShip($id) |
|
77
|
|
|
{ |
|
78
|
|
|
foreach (self::$ships as $ship) { |
|
79
|
|
|
if ($ship['id'] == $id) { |
|
80
|
|
|
return $ship; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
return null; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public static function getShips() |
|
88
|
|
|
{ |
|
89
|
|
|
return self::$ships; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public static function getFaction($id) |
|
93
|
|
|
{ |
|
94
|
|
|
if ($id == 'rebels') { |
|
95
|
|
|
return self::$factions[1]; |
|
96
|
|
|
} elseif($id == 'empire') { |
|
97
|
|
|
return self::$factions[2]; |
|
98
|
|
|
} |
|
99
|
|
|
if (array_key_exists($id, self::$factions)) { |
|
100
|
|
|
return self::$factions[$id]; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
return null; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|