|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
/** |
|
4
|
|
|
* Created by PhpStorm. |
|
5
|
|
|
* User: benedikt |
|
6
|
|
|
* Date: 10/1/17 |
|
7
|
|
|
* Time: 1:11 PM |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Tfboe\FmLib\Tests\Unit\Entity\Traits; |
|
11
|
|
|
|
|
12
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
13
|
|
|
use Doctrine\Common\Collections\Collection; |
|
14
|
|
|
use Tfboe\FmLib\Entity\CompetitionInterface; |
|
15
|
|
|
use Tfboe\FmLib\Entity\TeamInterface; |
|
16
|
|
|
use Tfboe\FmLib\Entity\TeamMembershipInterface; |
|
17
|
|
|
use Tfboe\FmLib\Tests\Entity\Team; |
|
18
|
|
|
use Tfboe\FmLib\Tests\Helpers\UnitTestCase; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class TournamentTest |
|
22
|
|
|
* @package Tfboe\FmLib\Tests\Unit\Entity |
|
23
|
|
|
*/ |
|
24
|
|
View Code Duplication |
class TeamTest extends UnitTestCase |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
//<editor-fold desc="Public Methods"> |
|
27
|
|
|
/** |
|
28
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Team::setCompetition |
|
29
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Team::getCompetition |
|
30
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Team::init |
|
31
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Team::getStartNumber |
|
32
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Team::setStartNumber |
|
33
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
|
34
|
|
|
*/ |
|
35
|
|
|
public function testCompetition() |
|
36
|
|
|
{ |
|
37
|
|
|
$team = $this->team(); |
|
38
|
|
|
$competition = $this->createStub(CompetitionInterface::class, ['getTeams' => new ArrayCollection()]); |
|
39
|
|
|
$team->setStartNumber(1); |
|
40
|
|
|
/** @var CompetitionInterface $competition */ |
|
41
|
|
|
$team->setCompetition($competition); |
|
42
|
|
|
self::assertEquals($competition, $team->getCompetition()); |
|
43
|
|
|
self::assertEquals(1, $team->getCompetition()->getTeams()->count()); |
|
44
|
|
|
self::assertEquals($team, $team->getCompetition()->getTeams()[$team->getStartNumber()]); |
|
45
|
|
|
|
|
46
|
|
|
$competition2 = $this->createStub(CompetitionInterface::class, ['getTeams' => new ArrayCollection()]); |
|
47
|
|
|
|
|
48
|
|
|
/** @var CompetitionInterface $competition2 */ |
|
49
|
|
|
$team->setCompetition($competition2); |
|
50
|
|
|
self::assertEquals($competition2, $team->getCompetition()); |
|
51
|
|
|
self::assertEquals(1, $team->getCompetition()->getTeams()->count()); |
|
52
|
|
|
self::assertEquals(0, $competition->getTeams()->count()); |
|
53
|
|
|
self::assertEquals($team, $team->getCompetition()->getTeams()[$team->getStartNumber()]); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Team::init |
|
58
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\NameEntity::getName |
|
59
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Team::getMemberships |
|
60
|
|
|
*/ |
|
61
|
|
|
public function testConstructor() |
|
62
|
|
|
{ |
|
63
|
|
|
$team = $this->team(); |
|
64
|
|
|
self::assertInstanceOf(Team::class, $team); |
|
65
|
|
|
self::assertInstanceOf(Collection::class, $team->getMemberships()); |
|
66
|
|
|
self::assertEquals(0, $team->getMemberships()->count()); |
|
67
|
|
|
self::assertEquals("", $team->getName()); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Team::getMemberships |
|
72
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Team::init |
|
73
|
|
|
*/ |
|
74
|
|
|
public function testPlayers() |
|
75
|
|
|
{ |
|
76
|
|
|
$team = $this->team(); |
|
77
|
|
|
/** @var TeamMembershipInterface $membership */ |
|
78
|
|
|
$membership = $this->createStubWithId(TeamMembershipInterface::class, 1, 'getId'); |
|
79
|
|
|
$team->getMemberships()->set($membership->getId(), $membership); |
|
80
|
|
|
self::assertEquals(1, $team->getMemberships()->count()); |
|
81
|
|
|
self::assertEquals($membership, $team->getMemberships()[$membership->getId()]); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Team::setRank |
|
86
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Team::getRank |
|
87
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Team::init |
|
88
|
|
|
*/ |
|
89
|
|
|
public function testRank() |
|
90
|
|
|
{ |
|
91
|
|
|
$team = $this->team(); |
|
92
|
|
|
$team->setRank(1); |
|
93
|
|
|
self::assertEquals(1, $team->getRank()); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Team::setStartNumber |
|
98
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Team::getStartNumber |
|
99
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Team::init |
|
100
|
|
|
*/ |
|
101
|
|
|
public function testStartNumber() |
|
102
|
|
|
{ |
|
103
|
|
|
$team = $this->team(); |
|
104
|
|
|
$team->setStartNumber(1); |
|
105
|
|
|
self::assertEquals(1, $team->getStartNumber()); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
//</editor-fold desc="Public Methods"> |
|
109
|
|
|
|
|
110
|
|
|
//<editor-fold desc="Private Methods"> |
|
111
|
|
|
/** |
|
112
|
|
|
* @return TeamInterface a new team |
|
113
|
|
|
*/ |
|
114
|
|
|
private function team(): TeamInterface |
|
115
|
|
|
{ |
|
116
|
|
|
return new Team(); |
|
117
|
|
|
} |
|
118
|
|
|
//</editor-fold desc="Private Methods"> |
|
119
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.