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\MatchInterface; |
16
|
|
|
use Tfboe\FmLib\Entity\Traits\Game; |
17
|
|
|
use Tfboe\FmLib\Helpers\Level; |
18
|
|
|
use Tfboe\FmLib\Tests\Entity\Player; |
19
|
|
|
use Tfboe\FmLib\Tests\Helpers\UnitTestCase; |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class GameTest |
24
|
|
|
* @package Tfboe\FmLib\Tests\Unit\Entity |
25
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods) |
26
|
|
|
*/ |
27
|
|
|
class GameTest extends UnitTestCase |
28
|
|
|
{ |
29
|
|
|
//<editor-fold desc="Public Methods"> |
30
|
|
|
/** |
31
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Game::getChildren |
32
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Game::init |
33
|
|
|
*/ |
34
|
|
|
public function testChildren() |
35
|
|
|
{ |
36
|
|
|
$game = $this->game(); |
37
|
|
|
self::callProtectedMethod($game, 'init'); |
38
|
|
|
self::assertEmpty($game->getChildren()); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Game::setGameNumber |
43
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Game::getGameNumber |
44
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Game::getLocalIdentifier |
45
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
46
|
|
|
*/ |
47
|
|
|
public function testGameNumberAndLocalIdentifier() |
48
|
|
|
{ |
49
|
|
|
$game = $this->game(); |
50
|
|
|
$gameNumber = 1; |
51
|
|
|
$game->setGameNumber($gameNumber); |
|
|
|
|
52
|
|
|
self::assertEquals($gameNumber, $game->getGameNumber()); |
|
|
|
|
53
|
|
|
self::assertEquals($game->getGameNumber(), $game->getLocalIdentifier()); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Game::init |
58
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Game::getPlayersA |
59
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Game::getPlayersB |
60
|
|
|
*/ |
61
|
|
View Code Duplication |
public function testInit() |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
$game = $this->game(); |
64
|
|
|
self::callProtectedMethod($game, 'init'); |
65
|
|
|
self::assertInstanceOf(Collection::class, $game->getPlayersA()); |
|
|
|
|
66
|
|
|
self::assertInstanceOf(Collection::class, $game->getPlayersB()); |
|
|
|
|
67
|
|
|
self::assertEquals(0, $game->getPlayersA()->count()); |
68
|
|
|
self::assertEquals(0, $game->getPlayersB()->count()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Game::getLevel |
73
|
|
|
*/ |
74
|
|
|
public function testLevel() |
75
|
|
|
{ |
76
|
|
|
self::assertEquals(Level::GAME, $this->game()->getLevel()); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Game::setMatch |
81
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Game::getMatch |
82
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Game::getParent |
83
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Game::getGameNumber |
84
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Game::setGameNumber |
85
|
|
|
*/ |
86
|
|
View Code Duplication |
public function testMatchAndParent() |
|
|
|
|
87
|
|
|
{ |
88
|
|
|
$game = $this->game(); |
89
|
|
|
$match = $this->createMock(MatchInterface::class); |
90
|
|
|
$games = new ArrayCollection(); |
91
|
|
|
$match->method('getGames')->willReturn($games); |
|
|
|
|
92
|
|
|
$game->setGameNumber(1); |
|
|
|
|
93
|
|
|
|
94
|
|
|
/** @var MatchInterface $match */ |
95
|
|
|
$game->setMatch($match); |
|
|
|
|
96
|
|
|
self::assertEquals($match, $game->getMatch()); |
|
|
|
|
97
|
|
|
self::assertEquals(1, $game->getMatch()->getGames()->count()); |
98
|
|
|
self::assertEquals($game, $game->getMatch()->getGames()[$game->getGameNumber()]); |
|
|
|
|
99
|
|
|
self::assertEquals($game->getMatch(), $game->getParent()); |
|
|
|
|
100
|
|
|
|
101
|
|
|
$match2 = $this->createMock(MatchInterface::class); |
102
|
|
|
$games2 = new ArrayCollection(); |
103
|
|
|
$match2->method('getGames')->willReturn($games2); |
|
|
|
|
104
|
|
|
|
105
|
|
|
/** @var MatchInterface $match2 */ |
106
|
|
|
$game->setMatch($match2); |
107
|
|
|
self::assertEquals($match2, $game->getMatch()); |
108
|
|
|
self::assertEquals(1, $game->getMatch()->getGames()->count()); |
109
|
|
|
self::assertEquals(0, $match->getGames()->count()); |
110
|
|
|
self::assertEquals($game, $game->getMatch()->getGames()[$game->getGameNumber()]); |
111
|
|
|
self::assertEquals($game->getMatch(), $game->getParent()); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Game::getPlayersA |
116
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Game::init |
117
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
118
|
|
|
*/ |
119
|
|
|
public function testPlayersA() |
120
|
|
|
{ |
121
|
|
|
$game = $this->game(); |
122
|
|
|
self::callProtectedMethod($game, 'init'); |
123
|
|
|
/** @var Player $player */ |
124
|
|
|
$player = $this->createStubWithId(Player::class, 1, 'getId'); |
125
|
|
|
$game->getPlayersA()->set($player->getId(), $player); |
|
|
|
|
126
|
|
|
self::assertEquals(1, $game->getPlayersA()->count()); |
127
|
|
|
self::assertEquals($player, $game->getPlayersA()[$player->getId()]); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Game::getPlayersB |
132
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Game::init |
133
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
134
|
|
|
*/ |
135
|
|
|
public function testPlayersB() |
136
|
|
|
{ |
137
|
|
|
$game = $this->game(); |
138
|
|
|
self::callProtectedMethod($game, 'init'); |
139
|
|
|
/** @var Player $player */ |
140
|
|
|
$player = $this->createStubWithId(Player::class, 1, 'getId'); |
141
|
|
|
$game->getPlayersB()->set($player->getId(), $player); |
|
|
|
|
142
|
|
|
self::assertEquals(1, $game->getPlayersB()->count()); |
143
|
|
|
self::assertEquals($player, $game->getPlayersB()[$player->getId()]); |
144
|
|
|
} |
145
|
|
|
//</editor-fold desc="Public Methods"> |
146
|
|
|
|
147
|
|
|
//<editor-fold desc="Private Methods"> |
148
|
|
|
/** |
149
|
|
|
* @return Game|MockObject a new game |
150
|
|
|
*/ |
151
|
|
|
private function game(): MockObject |
152
|
|
|
{ |
153
|
|
|
return $this->getMockForTrait(Game::class); |
154
|
|
|
} |
155
|
|
|
//</editor-fold desc="Private Methods"> |
156
|
|
|
} |
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: