1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace OSS\CoreBundle\Tests\Entity;
|
4
|
|
|
|
5
|
|
|
use OSS\CoreBundle\Entity\Manager;
|
6
|
|
|
use OSS\CoreBundle\Entity\Player;
|
7
|
|
|
use OSS\CoreBundle\Entity\PlayerSkills;
|
8
|
|
|
use OSS\CoreBundle\Entity\Team;
|
9
|
|
|
use OSS\CoreBundle\Entity\Trainer;
|
10
|
|
|
|
11
|
|
|
class TeamTest extends \PHPUnit_Framework_TestCase
|
12
|
|
|
{
|
13
|
|
|
/**
|
14
|
|
|
* @var Team
|
15
|
|
|
*/
|
16
|
|
|
private $team;
|
17
|
|
|
|
18
|
|
|
public function setUp()
|
19
|
|
|
{
|
20
|
|
|
$this->team = new Team();
|
21
|
|
|
}
|
22
|
|
|
|
23
|
|
|
public function tearDown()
|
24
|
|
|
{
|
25
|
|
|
$this->team = null;
|
26
|
|
|
}
|
27
|
|
|
|
28
|
|
|
public function testEquals()
|
29
|
|
|
{
|
30
|
|
|
$compareTeam = new Team();
|
31
|
|
|
|
32
|
|
|
$this->assertTrue($this->team->equals($compareTeam));
|
33
|
|
|
|
34
|
|
|
$this->team->setId(1);
|
35
|
|
|
$compareTeam->setId(2);
|
36
|
|
|
$this->assertFalse($this->team->equals($compareTeam));
|
37
|
|
|
}
|
38
|
|
|
|
39
|
|
|
public function testAddPlayer()
|
40
|
|
|
{
|
41
|
|
|
$this->assertCount(0, $this->team->getPlayers());
|
42
|
|
|
|
43
|
|
|
$player1 = new Player();
|
44
|
|
|
$player1->setId(1);
|
45
|
|
|
$this->team->addPlayer($player1);
|
46
|
|
|
$this->assertCount(1, $this->team->getPlayers());
|
47
|
|
|
$this->assertEquals($this->team, $player1->getTeam());
|
48
|
|
|
$this->assertContains($player1, $this->team->getPlayers());
|
49
|
|
|
|
50
|
|
|
$player2 = new Player();
|
51
|
|
|
$player2->setId(1);
|
52
|
|
|
$this->team->addPlayer($player2);
|
53
|
|
|
$this->assertCount(2, $this->team->getPlayers());
|
54
|
|
|
$this->assertEquals($this->team, $player1->getTeam());
|
55
|
|
|
$this->assertEquals($this->team, $player2->getTeam());
|
56
|
|
|
$this->assertContains($player1, $this->team->getPlayers());
|
57
|
|
|
$this->assertContains($player2, $this->team->getPlayers());
|
58
|
|
|
}
|
59
|
|
|
|
60
|
|
|
public function testGetRandomPlayer()
|
61
|
|
|
{
|
62
|
|
|
$player1 = new Player();
|
63
|
|
|
$player1->setId(1);
|
64
|
|
|
$this->team->addPlayer($player1);
|
65
|
|
|
|
66
|
|
|
$player2 = new Player();
|
67
|
|
|
$player2->setId(2);
|
68
|
|
|
$this->team->addPlayer($player2);
|
69
|
|
|
|
70
|
|
|
$this->assertContains($this->team->getRandomPlayer(), array($player1, $player2));
|
71
|
|
|
}
|
72
|
|
|
|
73
|
|
|
public function testResetPointsAndGoals()
|
74
|
|
|
{
|
75
|
|
|
$this->team->setPoints(1);
|
76
|
|
|
$this->team->setGoalsFor(1);
|
77
|
|
|
$this->team->setGoalsAgainst(1);
|
78
|
|
|
|
79
|
|
|
$this->team->resetPointsAndGoals();
|
80
|
|
|
|
81
|
|
|
$this->assertEquals(0, $this->team->getPoints());
|
82
|
|
|
$this->assertEquals(0, $this->team->getGoalsFor());
|
83
|
|
|
$this->assertEquals(0, $this->team->getGoalsAgainst());
|
84
|
|
|
}
|
85
|
|
|
|
86
|
|
|
public function testLineup()
|
87
|
|
|
{
|
88
|
|
|
$skills1 = new PlayerSkills();
|
89
|
|
|
$skills1->setAll(40);
|
90
|
|
|
$player1 = new Player();
|
91
|
|
|
$player1->setId(1);
|
92
|
|
|
$player1->setSkills($skills1);
|
93
|
|
|
$this->team->addPlayer($player1);
|
94
|
|
|
for ($i = 2; $i <= 12; $i++) {
|
95
|
|
|
$skills = new PlayerSkills();
|
96
|
|
|
$skills->setAll(50);
|
97
|
|
|
$player = new Player();
|
98
|
|
|
$player->setId($i);
|
99
|
|
|
$player->setSkills($skills);
|
100
|
|
|
$this->team->addPlayer($player);
|
101
|
|
|
}
|
102
|
|
|
$skills2 = new PlayerSkills();
|
103
|
|
|
$skills2->setAll(40);
|
104
|
|
|
$player2 = new Player();
|
105
|
|
|
$player2->setId(13);
|
106
|
|
|
$player2->setSkills($skills2);
|
107
|
|
|
$this->team->addPlayer($player2);
|
108
|
|
|
|
109
|
|
|
$this->assertCount(11, $this->team->getLineup());
|
110
|
|
|
$this->assertNotContains($player1, $this->team->getLineup());
|
111
|
|
|
$this->assertNotContains($player2, $this->team->getLineup());
|
112
|
|
|
}
|
113
|
|
|
|
114
|
|
|
public function testGetTrainer()
|
115
|
|
|
{
|
116
|
|
|
$this->assertNull($this->team->getTrainer());
|
117
|
|
|
}
|
118
|
|
|
|
119
|
|
|
public function testSetAndGetTrainer()
|
120
|
|
|
{
|
121
|
|
|
$trainer = new Trainer();
|
122
|
|
|
$this->team->setTrainer($trainer);
|
123
|
|
|
$this->assertEquals($trainer, $this->team->getTrainer());
|
124
|
|
|
$this->assertEquals($this->team, $trainer->getTeam());
|
125
|
|
|
}
|
126
|
|
|
|
127
|
|
|
public function testHasTrainer()
|
128
|
|
|
{
|
129
|
|
|
$this->assertFalse($this->team->hasTrainer());
|
130
|
|
|
$this->team->setTrainer(new Trainer());
|
131
|
|
|
$this->assertTrue($this->team->hasTrainer());
|
132
|
|
|
}
|
133
|
|
|
|
134
|
|
|
public function testGetManager()
|
135
|
|
|
{
|
136
|
|
|
$this->assertNull($this->team->getManager());
|
137
|
|
|
}
|
138
|
|
|
|
139
|
|
|
public function testSetAndGetManager()
|
140
|
|
|
{
|
141
|
|
|
$manager = new Manager();
|
142
|
|
|
$this->team->setManager($manager);
|
143
|
|
|
$this->assertEquals($manager, $this->team->getManager());
|
144
|
|
|
$this->assertEquals($this->team, $manager->getTeam());
|
145
|
|
|
}
|
146
|
|
|
|
147
|
|
|
public function testHasManager()
|
148
|
|
|
{
|
149
|
|
|
$this->assertFalse($this->team->hasManager());
|
150
|
|
|
$this->team->setManager(new Manager());
|
151
|
|
|
$this->assertTrue($this->team->hasManager());
|
152
|
|
|
}
|
153
|
|
|
|
154
|
|
|
public function testHandleTraining()
|
155
|
|
|
{
|
156
|
|
|
$player1 = new Player();
|
157
|
|
|
$skills1 = new PlayerSkills();
|
158
|
|
|
$player1->setSkills($skills1);
|
159
|
|
|
$this->team->setTrainer(new Trainer());
|
160
|
|
|
$this->team->addPlayer($player1);
|
161
|
|
|
$skills = new PlayerSkills();
|
162
|
|
|
$skills->setAllTrainingValues(10);
|
163
|
|
|
$player = new Player();
|
164
|
|
|
$player->setSkills($skills);
|
165
|
|
|
$this->team->addPlayer($player);
|
166
|
|
|
|
167
|
|
|
$this->team->train();
|
168
|
|
|
$players = $this->team->getPlayers();
|
169
|
|
|
$this->assertEquals(1, $players[0]->getSkills()->getTrainingValueTackling());
|
170
|
|
|
$this->assertEquals(11, $players[1]->getSkills()->getTrainingValueTackling());
|
171
|
|
|
}
|
172
|
|
|
|
173
|
|
|
public function testHandleTrainingWithoutTrainer()
|
174
|
|
|
{
|
175
|
|
|
$player = new Player();
|
176
|
|
|
$skills = new PlayerSkills();
|
177
|
|
|
$player->setSkills($skills);
|
178
|
|
|
$this->team->addPlayer($player);
|
179
|
|
|
|
180
|
|
|
$this->team->train();
|
181
|
|
|
$players = $this->team->getPlayers();
|
182
|
|
|
$this->assertEquals(0, $players[0]->getSkills()->getTrainingValueTackling());
|
183
|
|
|
$this->assertEquals(0, $players[0]->getSkills()->getTrainingValueTackling());
|
184
|
|
|
}
|
185
|
|
|
|
186
|
|
|
public function testSendMoney()
|
187
|
|
|
{
|
188
|
|
|
$this->team->setMoney(1000);
|
189
|
|
|
$targetTeam = new Team();
|
190
|
|
|
$this->team->sendMoney($targetTeam, 500);
|
191
|
|
|
$this->assertEquals(500, $this->team->getMoney());
|
192
|
|
|
$this->assertEquals(500, $targetTeam->getMoney());
|
193
|
|
|
}
|
194
|
|
|
}
|
195
|
|
|
|