1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
|
4
|
|
|
/**
|
5
|
|
|
* Class OrmModelsTest
|
6
|
|
|
*/
|
7
|
|
|
class OrmModelsTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
8
|
|
|
{
|
9
|
|
|
|
10
|
|
|
|
11
|
|
|
/**
|
12
|
|
|
* @group OrmModels
|
13
|
|
|
* @group PlayerOrm
|
14
|
|
|
*/
|
15
|
|
|
public function testPlayerOrmGetSet()
|
16
|
|
|
{
|
17
|
|
|
$rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller();
|
18
|
|
|
$playerM = $rndFiller->getPlayer();
|
19
|
|
|
$arrayPl = $playerM->toArray();
|
20
|
|
|
$playerO = \App\Lib\DsManager\Models\Orm\Player::create($arrayPl);
|
21
|
|
|
$this->assertNotEmpty($playerO);
|
22
|
|
|
|
23
|
|
|
$newPlayer = \App\Lib\DsManager\Models\Player::fromArray($playerO->toArray());
|
24
|
|
|
$this->assertNotEmpty($newPlayer);
|
25
|
|
|
}
|
26
|
|
|
|
27
|
|
|
/**
|
28
|
|
|
* @group OrmModels
|
29
|
|
|
* @group CoachOrm
|
30
|
|
|
*/
|
31
|
|
|
public function testCoachOrmGetSet()
|
32
|
|
|
{
|
33
|
|
|
$rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller();
|
34
|
|
|
$coach = $rndFiller->getCoach();
|
35
|
|
|
$arrayPl = $coach->toArray();
|
36
|
|
|
$coachO = \App\Lib\DsManager\Models\Orm\Coach::create($arrayPl);
|
37
|
|
|
$this->assertNotEmpty($coachO);
|
38
|
|
|
|
39
|
|
|
$newCoach = \App\Lib\DsManager\Models\Coach::fromArray($coachO->toArray());
|
40
|
|
|
$this->assertNotEmpty($newCoach);
|
41
|
|
|
}
|
42
|
|
|
|
43
|
|
|
/**
|
44
|
|
|
* @group OrmModels
|
45
|
|
|
* @group TeamOrm
|
46
|
|
|
*/
|
47
|
|
|
public function testTeamOrm()
|
48
|
|
|
{
|
49
|
|
|
$rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller();
|
50
|
|
|
$team = $rndFiller->getTeam($rndFiller->getLocale());
|
51
|
|
|
$teamArray = $team->toArray();
|
52
|
|
|
$this->assertNotEmpty($team);
|
53
|
|
|
$teamO = \App\Lib\DsManager\Models\Orm\Team::create($teamArray);
|
54
|
|
|
$this->assertNotEmpty($teamArray);
|
55
|
|
|
$this->assertNotEmpty($teamArray['roster']);
|
56
|
|
|
foreach ($teamArray['roster'] as $player) {
|
57
|
|
|
$player['team_id'] = $teamO->id;
|
|
|
|
|
58
|
|
|
$playerO = \App\Lib\DsManager\Models\Orm\Player::create($player);
|
59
|
|
|
$this->assertNotEmpty($playerO);
|
60
|
|
|
}
|
61
|
|
|
$teamArray['coach']['team_id'] = $teamO->id;
|
|
|
|
|
62
|
|
|
$coachO = \App\Lib\DsManager\Models\Orm\Coach::create($teamArray['coach']);
|
63
|
|
|
$this->assertNotEmpty($coachO);
|
64
|
|
|
|
65
|
|
|
$this->assertNotEmpty(
|
66
|
|
|
\App\Lib\DsManager\Models\Orm\Team::with(
|
67
|
|
|
'roster'
|
68
|
|
|
)->with(
|
69
|
|
|
'coach'
|
70
|
|
|
)->where(
|
71
|
|
|
[
|
72
|
|
|
'id' => $teamO->id
|
|
|
|
|
73
|
|
|
]
|
74
|
|
|
)->get()->toArray()
|
75
|
|
|
);
|
76
|
|
|
}
|
77
|
|
|
|
78
|
|
|
/**
|
79
|
|
|
* @group Match
|
80
|
|
|
* @group createnewmatch
|
81
|
|
|
*/
|
82
|
|
|
public function testCreateNewMatch()
|
83
|
|
|
{
|
84
|
|
|
$teams = \App\Lib\DsManager\Models\Orm\Team::with(
|
|
|
|
|
85
|
|
|
'roster',
|
86
|
|
|
'coach'
|
87
|
|
|
)->get();
|
88
|
|
|
$this->assertNotNull($teams);
|
89
|
|
|
$teams = $teams->toArray();
|
90
|
|
|
$homeIndex = array_rand($teams);
|
91
|
|
|
$teamHome = $teams[$homeIndex];
|
92
|
|
|
unset($teams[$homeIndex]);
|
93
|
|
|
$teamAway = $teams[array_rand($teams)];
|
94
|
|
|
$this->assertNotNull($teamHome);
|
95
|
|
|
$this->assertNotNull($teamAway);
|
96
|
|
|
$matchO = \App\Lib\DsManager\Models\Orm\Match::create(
|
97
|
|
|
[
|
98
|
|
|
'home_team_id' => $teamHome['id'],
|
99
|
|
|
'away_team_id' => $teamAway['id']
|
100
|
|
|
]
|
101
|
|
|
);
|
102
|
|
|
$this->assertNotNull($matchO);
|
103
|
|
|
$matchNew = \App\Lib\DsManager\Models\Orm\Match::complete()->where('id', $matchO->id)->first();
|
|
|
|
|
104
|
|
|
$this->assertNotNull($matchNew);
|
105
|
|
|
$match = \App\Lib\DsManager\Models\Match::fromArray($matchNew->toArray());
|
106
|
|
|
$this->assertNotNull($match);
|
107
|
|
|
}
|
108
|
|
|
|
109
|
|
|
/**
|
110
|
|
|
* @group Stats
|
111
|
|
|
*/
|
112
|
|
|
public function testGetStats()
|
113
|
|
|
{
|
114
|
|
|
$match = \App\Lib\DsManager\Models\Orm\Match::where(
|
115
|
|
|
[
|
116
|
|
|
'simulated' => false
|
117
|
|
|
]
|
118
|
|
|
)->whereNotNull(
|
119
|
|
|
'league_round_id'
|
120
|
|
|
)->get()->random(1);
|
121
|
|
|
$this->assertNotEmpty($match);
|
122
|
|
|
$result = \App\Lib\DsManager\Helpers\MatchSimulator::simulateRound($match->league_round_id);
|
123
|
|
|
$this->assertNotEmpty($result);
|
124
|
|
|
$players = \App\Lib\DsManager\Models\Orm\Player::getBest();
|
125
|
|
|
$this->assertNotEmpty($players);
|
126
|
|
|
$teams = \App\Lib\DsManager\Models\Orm\Team::getBest();
|
127
|
|
|
$this->assertNotEmpty($teams);
|
128
|
|
|
}
|
129
|
|
|
}
|
130
|
|
|
|
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.