|
1
|
|
|
<?php
|
|
2
|
|
|
|
|
3
|
|
|
namespace OSS\CoreBundle\Tests\Entity;
|
|
4
|
|
|
|
|
5
|
|
|
use OSS\CoreBundle\Entity\League;
|
|
6
|
|
|
use OSS\CoreBundle\Entity\Team;
|
|
7
|
|
|
|
|
8
|
|
|
class LeagueTest extends \PHPUnit_Framework_TestCase
|
|
9
|
|
|
{
|
|
10
|
|
|
public function testAddTeams()
|
|
11
|
|
|
{
|
|
12
|
|
|
$league = new League();
|
|
13
|
|
|
$team = new Team();
|
|
14
|
|
|
|
|
15
|
|
|
$league->addTeam($team);
|
|
16
|
|
|
$this->assertContains($team, $league->getStandings());
|
|
17
|
|
|
}
|
|
18
|
|
|
|
|
19
|
|
|
public function testBasicStandings()
|
|
20
|
|
|
{
|
|
21
|
|
|
$league = new League();
|
|
22
|
|
|
|
|
23
|
|
|
$team1 = new Team();
|
|
24
|
|
|
$team1->setId(1);
|
|
25
|
|
|
$team1->setPoints(1);
|
|
26
|
|
|
$league->addTeam($team1);
|
|
27
|
|
|
|
|
28
|
|
|
$team2 = new Team();
|
|
29
|
|
|
$team2->setId(2);
|
|
30
|
|
|
$team2->setPoints(3);
|
|
31
|
|
|
$league->addTeam($team2);
|
|
32
|
|
|
|
|
33
|
|
|
$standings = $league->getStandings();
|
|
34
|
|
|
|
|
35
|
|
|
$teamOnPosition1 = array_shift($standings);
|
|
36
|
|
|
$this->assertEquals(2, $teamOnPosition1->getId());
|
|
37
|
|
|
|
|
38
|
|
|
$teamOnPosition2 = array_shift($standings);
|
|
39
|
|
|
$this->assertEquals(1, $teamOnPosition2->getId());
|
|
40
|
|
|
|
|
41
|
|
|
$this->assertTrue($league->getTeamByPosition(1)->equals($team2));
|
|
42
|
|
|
$this->assertTrue($league->getTeamByPosition(2)->equals($team1));
|
|
43
|
|
|
}
|
|
44
|
|
|
|
|
45
|
|
|
public function testStandingsWithGoalsDifference()
|
|
46
|
|
|
{
|
|
47
|
|
|
$league = new League();
|
|
48
|
|
|
|
|
49
|
|
|
$team1 = new Team();
|
|
50
|
|
|
$team1->setId(1);
|
|
51
|
|
|
$team1->setPoints(1);
|
|
52
|
|
|
$team1->setGoalsFor(3);
|
|
53
|
|
|
$league->addTeam($team1);
|
|
54
|
|
|
|
|
55
|
|
|
$team2 = new Team();
|
|
56
|
|
|
$team2->setId(2);
|
|
57
|
|
|
$team2->setPoints(1);
|
|
58
|
|
|
$team2->setGoalsFor(5);
|
|
59
|
|
|
$league->addTeam($team2);
|
|
60
|
|
|
|
|
61
|
|
|
$this->assertTrue($league->getTeamByPosition(1)->equals($team2));
|
|
62
|
|
|
$this->assertTrue($league->getTeamByPosition(2)->equals($team1));
|
|
63
|
|
|
}
|
|
64
|
|
|
|
|
65
|
|
|
public function testStandingsWithGoalsFor()
|
|
66
|
|
|
{
|
|
67
|
|
|
$league = new League();
|
|
68
|
|
|
|
|
69
|
|
|
$team1 = new Team();
|
|
70
|
|
|
$team1->setId(1);
|
|
71
|
|
|
$team1->setPoints(1);
|
|
72
|
|
|
$team1->setGoalsFor(5);
|
|
73
|
|
|
$team1->setGoalsAgainst(3);
|
|
74
|
|
|
$league->addTeam($team1);
|
|
75
|
|
|
|
|
76
|
|
|
$team2 = new Team();
|
|
77
|
|
|
$team2->setId(2);
|
|
78
|
|
|
$team2->setPoints(1);
|
|
79
|
|
|
$team2->setGoalsFor(6);
|
|
80
|
|
|
$team2->setGoalsAgainst(4);
|
|
81
|
|
|
$league->addTeam($team2);
|
|
82
|
|
|
|
|
83
|
|
|
$this->assertTrue($league->getTeamByPosition(1)->equals($team2));
|
|
84
|
|
|
$this->assertTrue($league->getTeamByPosition(2)->equals($team1));
|
|
85
|
|
|
}
|
|
86
|
|
|
|
|
87
|
|
|
public function testGetPositionByTeam()
|
|
88
|
|
|
{
|
|
89
|
|
|
$league = new League();
|
|
90
|
|
|
|
|
91
|
|
|
$team1 = new Team();
|
|
92
|
|
|
$team1->setId(1);
|
|
93
|
|
|
$team1->setPoints(1);
|
|
94
|
|
|
$league->addTeam($team1);
|
|
95
|
|
|
|
|
96
|
|
|
$team2 = new Team();
|
|
97
|
|
|
$team2->setId(2);
|
|
98
|
|
|
$team2->setPoints(3);
|
|
99
|
|
|
$league->addTeam($team2);
|
|
100
|
|
|
|
|
101
|
|
|
$this->assertEquals(1, $league->getPositionByTeam($team2));
|
|
102
|
|
|
$this->assertEquals(2, $league->getPositionByTeam($team1));
|
|
103
|
|
|
}
|
|
104
|
|
|
}
|
|
105
|
|
|
|