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 PHPUnit\Framework\MockObject\MockObject; |
14
|
|
|
use Tfboe\FmLib\Entity\CompetitionInterface; |
15
|
|
|
use Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity; |
16
|
|
|
use Tfboe\FmLib\Entity\TournamentInterface; |
17
|
|
|
use Tfboe\FmLib\Entity\User; |
18
|
|
|
use Tfboe\FmLib\Helpers\Level; |
19
|
|
|
use Tfboe\FmLib\TestHelpers\UnitTestCase; |
20
|
|
|
|
21
|
|
|
/** @noinspection PhpMultipleClassesDeclarationsInOneFile */ |
22
|
|
|
abstract class Tournament extends TournamentHierarchyEntity implements TournamentInterface |
23
|
|
|
{ |
24
|
|
|
use \Tfboe\FmLib\Entity\Traits\Tournament; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** @noinspection PhpMultipleClassesDeclarationsInOneFile */ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Class TournamentTest |
31
|
|
|
* @package Tfboe\FmLib\Tests\Unit\Entity |
32
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods) |
33
|
|
|
*/ |
34
|
|
|
class TournamentTest extends UnitTestCase |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
//<editor-fold desc="Public Methods"> |
37
|
|
|
/** |
38
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Tournament::getCompetitions |
39
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Tournament::getChildren |
40
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\NameEntity::getName |
41
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\NameEntity::setName |
42
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Tournament::init |
43
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
44
|
|
|
*/ |
45
|
|
View Code Duplication |
public function testCompetitionsAndChildren() |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$tournament = $this->tournament(); |
48
|
|
|
$tournament->init(); |
|
|
|
|
49
|
|
|
$competition = $this->createStub(CompetitionInterface::class, ['getName' => 'comp name']); |
50
|
|
|
self::assertEquals($tournament->getCompetitions(), $tournament->getChildren()); |
|
|
|
|
51
|
|
|
/** @var CompetitionInterface $competition */ |
52
|
|
|
$tournament->getCompetitions()->set($competition->getName(), $competition); |
53
|
|
|
self::assertEquals(1, $tournament->getCompetitions()->count()); |
54
|
|
|
self::assertEquals($competition, $tournament->getCompetitions()[$competition->getName()]); |
55
|
|
|
self::assertEquals($tournament->getCompetitions(), $tournament->getChildren()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Tournament::init |
60
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Tournament::getCompetitions |
61
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Tournament::getTournamentListId |
62
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
63
|
|
|
*/ |
64
|
|
|
public function testConstructor() |
65
|
|
|
{ |
66
|
|
|
$tournament = $this->tournament(); |
67
|
|
|
$tournament->init(); |
|
|
|
|
68
|
|
|
self::assertInstanceOf(ArrayCollection::class, $tournament->getCompetitions()); |
|
|
|
|
69
|
|
|
self::assertEquals(0, $tournament->getCompetitions()->count()); |
70
|
|
|
self::assertEquals("", $tournament->getTournamentListId()); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Tournament::setCreator |
75
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Tournament::getCreator |
76
|
|
|
* @uses \Tfboe\FmLib\Entity\User::__construct |
77
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
78
|
|
|
*/ |
79
|
|
|
public function testCreator() |
80
|
|
|
{ |
81
|
|
|
$tournament = $this->tournament(); |
82
|
|
|
$creator = new User(); |
83
|
|
|
$tournament->setCreator($creator); |
|
|
|
|
84
|
|
|
self::assertEquals($creator, $tournament->getCreator()); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Tournament::getLocalIdentifier |
89
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\UUIDEntity::getId |
90
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
91
|
|
|
*/ |
92
|
|
|
public function testGetLocalIdentifier() |
93
|
|
|
{ |
94
|
|
|
$tournament = $this->tournament(); |
95
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */ |
96
|
|
|
self::getProperty(get_class($tournament), 'id')->setValue($tournament, 'user-id'); |
97
|
|
|
self::assertEquals($tournament->getId(), $tournament->getLocalIdentifier()); |
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Tournament::getLevel |
102
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
103
|
|
|
*/ |
104
|
|
|
public function testLevel() |
105
|
|
|
{ |
106
|
|
|
self::assertEquals(Level::TOURNAMENT, $this->tournament()->getLevel()); |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Tournament::getParent |
111
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
112
|
|
|
*/ |
113
|
|
|
public function testParent() |
114
|
|
|
{ |
115
|
|
|
self::assertNull($this->tournament()->getParent()); |
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Tournament::setTournamentListId |
120
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Tournament::getTournamentListId |
121
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
122
|
|
|
*/ |
123
|
|
|
public function testTournamentListId() |
124
|
|
|
{ |
125
|
|
|
$tournament = $this->tournament(); |
126
|
|
|
$tournament->setTournamentListId("Changed"); |
|
|
|
|
127
|
|
|
self::assertEquals("Changed", $tournament->getTournamentListId()); |
|
|
|
|
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Tournament::setUserIdentifier |
132
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Tournament::getUserIdentifier |
133
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
134
|
|
|
*/ |
135
|
|
|
public function testUserIdentifier() |
136
|
|
|
{ |
137
|
|
|
$tournament = $this->tournament(); |
138
|
|
|
$tournament->setUserIdentifier("UserIdentifier"); |
|
|
|
|
139
|
|
|
self::assertEquals("UserIdentifier", $tournament->getUserIdentifier()); |
|
|
|
|
140
|
|
|
} |
141
|
|
|
//</editor-fold desc="Public Methods"> |
142
|
|
|
|
143
|
|
|
//<editor-fold desc="Private Methods"> |
144
|
|
|
/** |
145
|
|
|
* @return Tournament|MockObject a new tournament |
146
|
|
|
*/ |
147
|
|
|
private function tournament(): MockObject |
148
|
|
|
{ |
149
|
|
|
return $this->getMockForAbstractClass(Tournament::class); |
150
|
|
|
} |
151
|
|
|
//</editor-fold desc="Private Methods"> |
152
|
|
|
} |
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.