1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Class ModelsTest |
6
|
|
|
*/ |
7
|
|
|
class ModelsTest extends \PHPUnit_Framework_TestCase |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @group Player |
13
|
|
|
*/ |
14
|
|
|
public function testGetRandomPlayer() |
15
|
|
|
{ |
16
|
|
|
$rndF = new \App\Lib\DsManager\Helpers\RandomFiller(); |
17
|
|
|
$player = $rndF->getPlayer(null, $rndF->getLocale()); |
18
|
|
|
$array = $player->toArray(); |
19
|
|
|
print_r($array); |
20
|
|
|
|
21
|
|
|
$newPlayer = \App\Lib\DsManager\Models\Player::fromArray($array); |
22
|
|
|
print_r($newPlayer->toArray()); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @group Coach |
27
|
|
|
*/ |
28
|
|
|
public function testGetRandomCoach() |
29
|
|
|
{ |
30
|
|
|
$rndF = new \App\Lib\DsManager\Helpers\RandomFiller(); |
31
|
|
|
$coach = $rndF->getCoach(); |
32
|
|
|
print_r($coach->toArray()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @group Coaches |
37
|
|
|
*/ |
38
|
|
View Code Duplication |
public function testGetRandomCoaches() |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
foreach (\App\Lib\Helpers\Config::get('generic.localesSmall', 'api/') as $nat) { |
|
|
|
|
41
|
|
|
$rndF = new \App\Lib\DsManager\Helpers\RandomFiller($nat); |
42
|
|
|
$coach = $rndF->getCoach(); |
43
|
|
|
print_r($coach->toArray()); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @group Players |
49
|
|
|
*/ |
50
|
|
View Code Duplication |
public function testGetRandomPlayers() |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
foreach (\App\Lib\Helpers\Config::get('generic.localesSmall', 'api/') as $nat) { |
|
|
|
|
53
|
|
|
$rndF = new \App\Lib\DsManager\Helpers\RandomFiller($nat); |
54
|
|
|
$player = $rndF->getPlayer(); |
55
|
|
|
print_r($player->toArray()); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @group Team |
61
|
|
|
*/ |
62
|
|
|
public function testGetRandomTeam() |
63
|
|
|
{ |
64
|
|
|
$rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
65
|
|
|
$team = $rndF->getTeam(); |
66
|
|
|
|
67
|
|
|
//var_dump($team->toArray()); |
|
|
|
|
68
|
|
|
echo "\n" . $team->name . " avg:"; |
69
|
|
|
echo $team->getAvgSkill(); |
70
|
|
|
|
71
|
|
|
echo "\n Adding player:"; |
72
|
|
|
$player = $rndF->getPlayer(); |
73
|
|
|
var_dump($player->toArray()); |
|
|
|
|
74
|
|
|
$team->roster[] = $player; |
75
|
|
|
echo "\n new avg: "; |
76
|
|
|
echo $team->getAvgSkill(); |
77
|
|
|
echo "\n age avg: "; |
78
|
|
|
echo $team->getAvgAge(); |
79
|
|
|
|
80
|
|
|
echo "\ncoach:"; |
81
|
|
|
print_r($team->coach->toArray()); |
82
|
|
|
|
83
|
|
|
$teamArray = $team->toArray(); |
84
|
|
|
print_r($teamArray); |
85
|
|
|
|
86
|
|
|
$newTeam = \App\Lib\DsManager\Models\Team::fromArray($teamArray); |
87
|
|
|
print_r($newTeam->toArray()); |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @group Teams |
93
|
|
|
*/ |
94
|
|
|
public function testGetRandomTeams() |
95
|
|
|
{ |
96
|
|
|
$rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
97
|
|
|
|
98
|
|
|
for ($i = 1; $i <= 20; $i++) { |
99
|
|
|
echo "\n\n-------------"; |
100
|
|
|
$team = $rndF->getTeam(); |
101
|
|
|
echo "\n team: " . $team->name; |
102
|
|
|
echo "\n nat: " . $team->nationality; |
103
|
|
|
echo "\n skill avg: "; |
104
|
|
|
echo $team->getAvgSkill(); |
105
|
|
|
echo "\n age avg: "; |
106
|
|
|
echo $team->getAvgAge(); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @group Match |
112
|
|
|
*/ |
113
|
|
|
public function testGetRandomMatch() |
114
|
|
|
{ |
115
|
|
|
for ($i = 1; $i <= 30; $i++) { |
116
|
|
|
$rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
117
|
|
|
$spanish = $rndF->getTeam(); |
118
|
|
|
$rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
119
|
|
|
$italian = $rndF->getTeam(); |
120
|
|
|
|
121
|
|
|
echo "\n" . $italian->name . "(" . $italian->getAvgSkill() . ") - " . $spanish->name . "(" . $spanish->getAvgSkill() . ") ...... "; |
122
|
|
|
$result = (new \App\Lib\DsManager\Models\Match($italian, $spanish))->simulate()->toArray(); |
123
|
|
|
echo $result['goalHome'] . " - " . $result['goalAway']; |
124
|
|
|
echo "\n\n"; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @group Matches |
131
|
|
|
*/ |
132
|
|
|
public function testGetRandomMatchesOneTeam() |
133
|
|
|
{ |
134
|
|
|
$rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
135
|
|
|
$myTeam = $rndF->getTeam(); |
136
|
|
|
$win = 0; |
137
|
|
|
$lost = 0; |
138
|
|
|
$draw = 0; |
139
|
|
|
|
140
|
|
|
for ($i = 1; $i <= 30; $i++) { |
141
|
|
|
|
142
|
|
|
$randomLocale = \App\Lib\Helpers\Config::get('generic.localesSmall', 'api/'); |
|
|
|
|
143
|
|
|
shuffle($randomLocale); |
144
|
|
|
$randomLocale = $randomLocale[0]; |
145
|
|
|
|
146
|
|
|
$rndF = new \App\Lib\DsManager\Helpers\RandomFiller($randomLocale); |
147
|
|
|
$opponent = $rndF->getTeam(); |
148
|
|
|
|
149
|
|
|
echo "\n" . $opponent->name . "(" . $opponent->getAvgSkill() . ") - " . $myTeam->name . "(" . $myTeam->getAvgSkill() . ") ...... "; |
150
|
|
|
$result = (new \App\Lib\DsManager\Models\Match($opponent, $myTeam))->simulate()->toArray(); |
151
|
|
|
echo $result['goalHome'] . " - " . $result['goalAway']; |
152
|
|
|
$result = $result['info']; |
153
|
|
|
if (!$result['isDraw']) { |
154
|
|
|
if ($result['winner']->name == $myTeam->name) { |
155
|
|
|
$win++; |
156
|
|
|
} else { |
157
|
|
|
$lost++; |
158
|
|
|
} |
159
|
|
|
} else { |
160
|
|
|
$draw++; |
161
|
|
|
} |
162
|
|
|
echo "\n"; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
echo "\nw:$win l:$lost d:$draw\n\n"; |
166
|
|
|
|
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @group Module |
171
|
|
|
*/ |
172
|
|
|
public function testModule() |
173
|
|
|
{ |
174
|
|
|
$rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT"); |
175
|
|
|
$team = $rndF->getTeam(); |
176
|
|
|
|
177
|
|
|
$modules = \App\Lib\Helpers\Config::get("modules.modules", "api/"); |
|
|
|
|
178
|
|
|
$modules = array_keys($modules); |
179
|
|
|
foreach ($modules as $mod) { |
180
|
|
|
$module = new \App\Lib\DsManager\Models\Module($mod); |
181
|
|
|
echo "\n------------\n\n" . $module; |
182
|
|
|
echo "\nD: " . $module->isDefensive(); |
183
|
|
|
echo "\nB: " . $module->isBalanced(); |
184
|
|
|
echo "\nO: " . $module->isOffensive(); |
185
|
|
|
echo "\n"; |
186
|
|
|
print_r($module->getRoleNeeded()); |
187
|
|
|
echo "\napplicable? "; |
188
|
|
|
if ($module->isApplicableToTeam($team)) { |
189
|
|
|
echo " yes"; |
190
|
|
|
} else { |
191
|
|
|
echo " no"; |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
echo "\n"; |
195
|
|
|
print_r($team->playersPerRoleArray()); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
} |
199
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.