1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace OSS\CoreBundle\Tests\Service;
|
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManager;
|
6
|
|
|
use OSS\CoreBundle\Entity\Event;
|
7
|
|
|
use OSS\CoreBundle\Entity\Fixture;
|
8
|
|
|
use OSS\CoreBundle\Entity\League;
|
9
|
|
|
use OSS\CoreBundle\Entity\Player;
|
10
|
|
|
use OSS\CoreBundle\Entity\Team;
|
11
|
|
|
use OSS\CoreBundle\Services\LeagueService;
|
12
|
|
|
|
13
|
|
|
class LeagueServiceTest extends \PHPUnit_Framework_TestCase
|
14
|
|
|
{
|
15
|
|
|
/**
|
16
|
|
|
* @var LeagueService
|
17
|
|
|
*/
|
18
|
|
|
private $leagueService;
|
19
|
|
|
|
20
|
|
|
public function setUp()
|
21
|
|
|
{
|
22
|
|
|
/** @var EntityManager $entityManager */
|
23
|
|
|
$entityManager = $this->getMockBuilder('Doctrine\ORM\EntityManager')->disableOriginalConstructor()->getMock();
|
24
|
|
|
$this->leagueService = new LeagueService($entityManager);
|
25
|
|
|
}
|
26
|
|
|
|
27
|
|
|
public function tearDown()
|
28
|
|
|
{
|
29
|
|
|
$this->leagueService = null;
|
30
|
|
|
}
|
31
|
|
|
|
32
|
|
|
public function testScorer()
|
33
|
|
|
{
|
34
|
|
|
$league = new League();
|
35
|
|
|
|
36
|
|
|
$team1 = new Team();
|
37
|
|
|
$team1->setId(1);
|
38
|
|
|
$league->addTeam($team1);
|
39
|
|
|
|
40
|
|
|
$player1 = new Player();
|
41
|
|
|
$player1->setId(1);
|
42
|
|
|
$player1->setTeam($team1);
|
43
|
|
|
|
44
|
|
|
$team2 = new Team();
|
45
|
|
|
$team2->setId(2);
|
46
|
|
|
$league->addTeam($team2);
|
47
|
|
|
|
48
|
|
|
$player2 = new Player();
|
49
|
|
|
$player2->setId(2);
|
50
|
|
|
$player2->setTeam($team2);
|
51
|
|
|
|
52
|
|
|
$fixture = new Fixture();
|
53
|
|
|
$fixture->setTeamHome($team1);
|
54
|
|
|
$fixture->setTeamAway($team2);
|
55
|
|
|
$league->addFixture($fixture);
|
56
|
|
|
|
57
|
|
|
$fixture->addEvent(Event::createGoal($fixture, $team1, $player1, 1));
|
58
|
|
|
$fixture->addEvent(Event::createGoal($fixture, $team1, $player1, 2));
|
59
|
|
|
$fixture->addEvent(Event::createGoal($fixture, $team2, $player2, 3));
|
60
|
|
|
|
61
|
|
|
$scorer = $this->leagueService->getScorer(array($fixture));
|
62
|
|
|
$this->assertEquals($player1, $scorer[0]->getPlayer());
|
63
|
|
|
$this->assertEquals($player2, $scorer[1]->getPlayer());
|
64
|
|
|
$this->assertEquals(2, $scorer[0]->getGoals());
|
65
|
|
|
$this->assertEquals(1, $scorer[1]->getGoals());
|
66
|
|
|
}
|
67
|
|
|
}
|
68
|
|
|
|