|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
/** |
|
4
|
|
|
* Created by PhpStorm. |
|
5
|
|
|
* User: benedikt |
|
6
|
|
|
* Date: 1/3/18 |
|
7
|
|
|
* Time: 10:39 AM |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Tfboe\FmLib\Tests\Unit\Entity\Traits; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
use Doctrine\Common\Collections\Collection; |
|
14
|
|
|
use Tfboe\FmLib\Entity\Helpers\AutomaticInstanceGeneration; |
|
15
|
|
|
use Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity; |
|
16
|
|
|
use Tfboe\FmLib\Entity\RankingSystemInterface; |
|
17
|
|
|
use Tfboe\FmLib\Entity\RankingSystemListInterface; |
|
18
|
|
|
use Tfboe\FmLib\Helpers\Level; |
|
19
|
|
|
use Tfboe\FmLib\Tests\Entity\RankingSystem; |
|
20
|
|
|
use Tfboe\FmLib\Tests\Entity\RankingSystemList; |
|
21
|
|
|
use Tfboe\FmLib\Tests\Helpers\UnitTestCase; |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class BaseEntityTest |
|
26
|
|
|
* @package Tfboe\FmLib\Tests\Unit\Entity\Helpers |
|
27
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods) |
|
28
|
|
|
*/ |
|
29
|
|
|
class RankingSystemTest extends UnitTestCase |
|
30
|
|
|
{ |
|
31
|
|
|
//<editor-fold desc="Public Methods"> |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\RankingSystem::setGenerationInterval |
|
35
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\RankingSystem::getGenerationInterval |
|
36
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\SubClassData::initSubClassData |
|
37
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\RankingSystem::init |
|
38
|
|
|
* @uses \Tfboe\FmLib\Helpers\BasicEnum |
|
39
|
|
|
*/ |
|
40
|
|
|
public function testAutomaticInstanceGeneration() |
|
41
|
|
|
{ |
|
42
|
|
|
$entity = $this->instance(); |
|
43
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */ |
|
44
|
|
|
$entity->setGenerationInterval(AutomaticInstanceGeneration::MONTHLY); |
|
45
|
|
|
self::assertEquals(AutomaticInstanceGeneration::MONTHLY, $entity->getGenerationInterval()); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\RankingSystem::init |
|
50
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\SubClassData::initSubClassData |
|
51
|
|
|
* @uses \Tfboe\FmLib\Helpers\BasicEnum |
|
52
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\RankingSystem::getGenerationInterval |
|
53
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\RankingSystem::getDefaultForLevel |
|
54
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\RankingSystem::getLists |
|
55
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\RankingSystem::getOpenSyncFrom |
|
56
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\RankingSystem::getHierarchyEntries |
|
57
|
|
|
*/ |
|
58
|
|
|
public function testConstructor() |
|
59
|
|
|
{ |
|
60
|
|
|
$entity = $this->instance(); |
|
61
|
|
|
self::assertInstanceOf(RankingSystem::class, $entity); |
|
62
|
|
|
self::assertEquals(AutomaticInstanceGeneration::OFF, $entity->getGenerationInterval()); |
|
63
|
|
|
self::assertNull($entity->getDefaultForLevel()); |
|
64
|
|
|
self::assertNull($entity->getOpenSyncFrom()); |
|
65
|
|
|
self::assertInstanceOf(Collection::class, $entity->getHierarchyEntries()); |
|
66
|
|
|
self::assertInstanceOf(Collection::class, $entity->getLists()); |
|
67
|
|
|
self::assertEquals(0, count($entity->getHierarchyEntries())); |
|
68
|
|
|
self::assertEquals(0, count($entity->getLists())); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\RankingSystem::setDefaultForLevel |
|
73
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\RankingSystem::getDefaultForLevel |
|
74
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\SubClassData::initSubClassData |
|
75
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\RankingSystem::init |
|
76
|
|
|
* @uses \Tfboe\FmLib\Helpers\BasicEnum |
|
77
|
|
|
*/ |
|
78
|
|
|
public function testDefaultForLevel() |
|
79
|
|
|
{ |
|
80
|
|
|
$entity = $this->instance(); |
|
81
|
|
|
$level = Level::COMPETITION; |
|
82
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */ |
|
83
|
|
|
$entity->setDefaultForLevel($level); |
|
84
|
|
|
self::assertEquals($level, $entity->getDefaultForLevel()); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\RankingSystem::getLists |
|
89
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\SubClassData::initSubClassData |
|
90
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\RankingSystem::init |
|
91
|
|
|
*/ |
|
92
|
|
View Code Duplication |
public function testLists() |
|
|
|
|
|
|
93
|
|
|
{ |
|
94
|
|
|
$entity = $this->instance(); |
|
95
|
|
|
/** @var RankingSystemListInterface $entity2 */ |
|
96
|
|
|
$entity2 = $this->createStubWithId(RankingSystemList::class); |
|
97
|
|
|
$entity->getLists()->set($entity2->getId(), $entity2); |
|
98
|
|
|
self::assertEquals(1, $entity->getLists()->count()); |
|
99
|
|
|
self::assertEquals($entity2, $entity->getLists()[$entity2->getId()]); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\RankingSystem::setOpenSyncFrom |
|
104
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\RankingSystem::getOpenSyncFrom |
|
105
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\SubClassData::initSubClassData |
|
106
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\RankingSystem::init |
|
107
|
|
|
*/ |
|
108
|
|
|
public function testOpenSyncFrom() |
|
109
|
|
|
{ |
|
110
|
|
|
$entity = $this->instance(); |
|
111
|
|
|
$entity->setOpenSyncFrom(new \DateTime("2017-01-01")); |
|
112
|
|
|
self::assertEquals(new \DateTime("2017-01-01"), $entity->getOpenSyncFrom()); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\RankingSystem::setServiceName |
|
117
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\RankingSystem::getServiceName |
|
118
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\SubClassData::initSubClassData |
|
119
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\RankingSystem::init |
|
120
|
|
|
*/ |
|
121
|
|
|
public function testServiceName() |
|
122
|
|
|
{ |
|
123
|
|
|
$entity = $this->instance(); |
|
124
|
|
|
$entity->setServiceName("serviceName"); |
|
125
|
|
|
self::assertEquals("serviceName", $entity->getServiceName()); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\RankingSystem::getHierarchyEntries |
|
130
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\SubClassData::initSubClassData |
|
131
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\RankingSystem::init |
|
132
|
|
|
*/ |
|
133
|
|
View Code Duplication |
public function testTournamentRankingEntities() |
|
|
|
|
|
|
134
|
|
|
{ |
|
135
|
|
|
$entity = $this->instance(); |
|
136
|
|
|
/** @var TournamentHierarchyEntity $entity2 */ |
|
137
|
|
|
$entity2 = $this->createStubWithId(TournamentHierarchyEntity::class); |
|
138
|
|
|
$entity->getHierarchyEntries()->set($entity2->getId(), $entity2); |
|
139
|
|
|
self::assertEquals(1, $entity->getHierarchyEntries()->count()); |
|
140
|
|
|
self::assertEquals($entity2, $entity->getHierarchyEntries()[$entity2->getId()]); |
|
141
|
|
|
} |
|
142
|
|
|
//</editor-fold desc="Public Methods"> |
|
143
|
|
|
|
|
144
|
|
|
//<editor-fold desc="Private Methods"> |
|
145
|
|
|
/** |
|
146
|
|
|
* @return RankingSystemInterface |
|
147
|
|
|
*/ |
|
148
|
|
|
private function instance(): RankingSystemInterface |
|
149
|
|
|
{ |
|
150
|
|
|
return new RankingSystem([]); |
|
151
|
|
|
} |
|
152
|
|
|
//</editor-fold desc="Private Methods"> |
|
153
|
|
|
} |
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.