|
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\Helpers\Level; |
|
18
|
|
|
use Tfboe\FmLib\Tests\Entity\User; |
|
19
|
|
|
use Tfboe\FmLib\Tests\Helpers\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
|
|
|
self::callProtectedMethod($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
|
|
|
self::callProtectedMethod($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\Traits\User::init |
|
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
|
|
|
//</editor-fold desc="Public Methods"> |
|
130
|
|
|
|
|
131
|
|
|
//<editor-fold desc="Private Methods"> |
|
132
|
|
|
/** |
|
133
|
|
|
* @return Tournament|MockObject a new tournament |
|
134
|
|
|
*/ |
|
135
|
|
|
private function tournament(): MockObject |
|
136
|
|
|
{ |
|
137
|
|
|
return $this->getMockForAbstractClass(Tournament::class); |
|
138
|
|
|
} |
|
139
|
|
|
//</editor-fold desc="Private Methods"> |
|
140
|
|
|
} |
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.