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 PHPUnit\Framework\MockObject\MockObject; |
15
|
|
|
use Tfboe\FmLib\Entity\GameInterface; |
16
|
|
|
use Tfboe\FmLib\Entity\PhaseInterface; |
17
|
|
|
use Tfboe\FmLib\Entity\Ranking; |
18
|
|
|
use Tfboe\FmLib\Entity\Traits\Match; |
19
|
|
|
use Tfboe\FmLib\Helpers\Level; |
20
|
|
|
use Tfboe\FmLib\TestHelpers\UnitTestCase; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class TournamentTest |
24
|
|
|
* @package Tfboe\FmLib\Tests\Unit\Entity |
25
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods) |
26
|
|
|
*/ |
27
|
|
|
class MatchTest extends UnitTestCase |
28
|
|
|
{ |
29
|
|
|
//<editor-fold desc="Public Methods"> |
30
|
|
|
/** |
31
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Match::getGames |
32
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Match::getChildren |
33
|
|
|
* @uses \Tfboe\FmLib\Entity\GameInterface |
34
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Match::init |
35
|
|
|
*/ |
36
|
|
|
public function testGamesAndChildren() |
37
|
|
|
{ |
38
|
|
|
$match = $this->match(); |
39
|
|
|
$match->init(); |
|
|
|
|
40
|
|
|
$game = $this->createMock(GameInterface::class); |
41
|
|
|
$game->method('getGameNumber')->willReturn(1); |
42
|
|
|
/** @var GameInterface $game */ |
43
|
|
|
self::assertEquals($match->getGames(), $match->getChildren()); |
|
|
|
|
44
|
|
|
$match->getGames()->set($game->getGameNumber(), $game); |
45
|
|
|
self::assertEquals(1, $match->getGames()->count()); |
46
|
|
|
self::assertEquals($game, $match->getGames()[1]); |
47
|
|
|
self::assertEquals($match->getGames(), $match->getChildren()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Match::init |
52
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
53
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Match::getGames |
54
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Match::getRankingsA |
55
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Match::getRankingsB |
56
|
|
|
*/ |
57
|
|
View Code Duplication |
public function testInit() |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
$match = $this->match(); |
60
|
|
|
$match->init(); |
|
|
|
|
61
|
|
|
self::assertInstanceOf(Collection::class, $match->getRankingsA()); |
|
|
|
|
62
|
|
|
self::assertInstanceOf(Collection::class, $match->getRankingsB()); |
|
|
|
|
63
|
|
|
self::assertInstanceOf(Collection::class, $match->getGames()); |
|
|
|
|
64
|
|
|
self::assertEquals(0, $match->getRankingsA()->count()); |
65
|
|
|
self::assertEquals(0, $match->getRankingsB()->count()); |
66
|
|
|
self::assertEquals(0, $match->getGames()->count()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Match::getLevel |
71
|
|
|
*/ |
72
|
|
|
public function testLevel() |
73
|
|
|
{ |
74
|
|
|
self::assertEquals(Level::MATCH, $this->match()->getLevel()); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Match::setMatchNumber |
79
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Match::getMatchNumber |
80
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Match::getLocalIdentifier |
81
|
|
|
*/ |
82
|
|
|
public function testMatchNumberAndLocalIdentifier() |
83
|
|
|
{ |
84
|
|
|
$match = $this->match(); |
85
|
|
|
$matchNumber = 1; |
86
|
|
|
$match->setMatchNumber($matchNumber); |
|
|
|
|
87
|
|
|
self::assertEquals($matchNumber, $match->getMatchNumber()); |
|
|
|
|
88
|
|
|
self::assertEquals($match->getMatchNumber(), $match->getLocalIdentifier()); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Match::setPhase |
93
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Match::getPhase |
94
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Match::getParent |
95
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Match::getMatchNumber |
96
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Match::setMatchNumber |
97
|
|
|
*/ |
98
|
|
|
public function testPhaseAndParent() |
99
|
|
|
{ |
100
|
|
|
$match = $this->match(); |
101
|
|
|
$phase = $this->createStub(PhaseInterface::class, ["getMatches" => new ArrayCollection()]); |
102
|
|
|
$match->setMatchNumber(1); |
|
|
|
|
103
|
|
|
/** @var PhaseInterface $phase */ |
104
|
|
|
$match->setPhase($phase); |
|
|
|
|
105
|
|
|
self::assertEquals($phase, $match->getPhase()); |
|
|
|
|
106
|
|
|
self::assertEquals(1, $match->getPhase()->getMatches()->count()); |
107
|
|
|
self::assertEquals($match, $match->getPhase()->getMatches()[$match->getMatchNumber()]); |
|
|
|
|
108
|
|
|
self::assertEquals($match->getPhase(), $match->getParent()); |
|
|
|
|
109
|
|
|
|
110
|
|
|
$phase2 = $this->createStub(PhaseInterface::class, ["getMatches" => new ArrayCollection()]); |
111
|
|
|
|
112
|
|
|
/** @var PhaseInterface $phase2 */ |
113
|
|
|
$match->setPhase($phase2); |
114
|
|
|
self::assertEquals($phase2, $match->getPhase()); |
115
|
|
|
self::assertEquals(1, $match->getPhase()->getMatches()->count()); |
116
|
|
|
self::assertEquals(0, $phase->getMatches()->count()); |
117
|
|
|
self::assertEquals($match, $match->getPhase()->getMatches()[$match->getMatchNumber()]); |
118
|
|
|
self::assertEquals($match->getPhase(), $match->getParent()); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Match::getRankingsA |
123
|
|
|
* @uses \Tfboe\FmLib\Entity\Ranking |
124
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Match::init |
125
|
|
|
*/ |
126
|
|
View Code Duplication |
public function testRankingsA() |
|
|
|
|
127
|
|
|
{ |
128
|
|
|
$match = $this->match(); |
129
|
|
|
$match->init(); |
|
|
|
|
130
|
|
|
$ranking = new Ranking(); |
131
|
|
|
$ranking->setUniqueRank(1); |
132
|
|
|
$match->getRankingsA()->set($ranking->getUniqueRank(), $ranking); |
|
|
|
|
133
|
|
|
self::assertEquals(1, $match->getRankingsA()->count()); |
134
|
|
|
self::assertEquals($ranking, $match->getRankingsA()[1]); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Match::getRankingsB |
139
|
|
|
* @uses \Tfboe\FmLib\Entity\Ranking |
140
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Match::init |
141
|
|
|
*/ |
142
|
|
View Code Duplication |
public function testRankingsB() |
|
|
|
|
143
|
|
|
{ |
144
|
|
|
$match = $this->match(); |
145
|
|
|
$match->init(); |
|
|
|
|
146
|
|
|
$ranking = new Ranking(); |
147
|
|
|
$ranking->setUniqueRank(1); |
148
|
|
|
$match->getRankingsB()->set($ranking->getUniqueRank(), $ranking); |
|
|
|
|
149
|
|
|
self::assertEquals(1, $match->getRankingsB()->count()); |
150
|
|
|
self::assertEquals($ranking, $match->getRankingsB()[1]); |
151
|
|
|
} |
152
|
|
|
//</editor-fold desc="Public Methods"> |
153
|
|
|
|
154
|
|
|
//<editor-fold desc="Private Methods"> |
155
|
|
|
/** |
156
|
|
|
* @return Match|MockObject a new match |
157
|
|
|
*/ |
158
|
|
|
private function match(): MockObject |
159
|
|
|
{ |
160
|
|
|
return $this->getMockForTrait(Match::class); |
161
|
|
|
} |
162
|
|
|
//</editor-fold desc="Private Methods"> |
163
|
|
|
} |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: