|
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\Team; |
|
16
|
|
|
use Tfboe\FmLib\Entity\TournamentInterface; |
|
17
|
|
|
use Tfboe\FmLib\Entity\Traits\Competition; |
|
18
|
|
|
use Tfboe\FmLib\Entity\Traits\Phase; |
|
|
|
|
|
|
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
|
|
|
*/ |
|
26
|
|
|
class CompetitionTest extends UnitTestCase |
|
27
|
|
|
{ |
|
28
|
|
|
//<editor-fold desc="Public Methods"> |
|
29
|
|
|
/** |
|
30
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Competition::getLocalIdentifier |
|
31
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\NameEntity::getName |
|
32
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\NameEntity::setName |
|
33
|
|
|
*/ |
|
34
|
|
|
public function testGetLocalIdentifier() |
|
35
|
|
|
{ |
|
36
|
|
|
$entity = $this->competition(); |
|
37
|
|
|
$entity->setName("Name"); |
|
|
|
|
|
|
38
|
|
|
self::assertEquals($entity->getName(), $entity->getLocalIdentifier()); |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Competition::init |
|
43
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Competition::getPhases |
|
44
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Competition::getTeams |
|
45
|
|
|
*/ |
|
46
|
|
|
public function testInit() |
|
47
|
|
|
{ |
|
48
|
|
|
$competition = $this->competition(); |
|
49
|
|
|
$competition->init(); |
|
|
|
|
|
|
50
|
|
|
self::assertInstanceOf(Collection::class, $competition->getTeams()); |
|
|
|
|
|
|
51
|
|
|
self::assertInstanceOf(Collection::class, $competition->getPhases()); |
|
|
|
|
|
|
52
|
|
|
self::assertEquals(0, $competition->getTeams()->count()); |
|
53
|
|
|
self::assertEquals(0, $competition->getPhases()->count()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Competition::getLevel() |
|
58
|
|
|
*/ |
|
59
|
|
|
public function testLevel() |
|
60
|
|
|
{ |
|
61
|
|
|
self::assertEquals(Level::COMPETITION, $this->competition()->getLevel()); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Competition::getPhases |
|
66
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Competition::getChildren |
|
67
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Phase |
|
68
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Competition::init |
|
69
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Competition::init |
|
70
|
|
|
*/ |
|
71
|
|
|
public function testPhasesAndChildren() |
|
72
|
|
|
{ |
|
73
|
|
|
$competition = $this->competition(); |
|
74
|
|
|
$competition->init(); |
|
|
|
|
|
|
75
|
|
|
/** @var Phase $phase */ |
|
76
|
|
|
$phase = $this->getMockForTrait(Phase::class); |
|
77
|
|
|
$phase->setPhaseNumber(1); |
|
78
|
|
|
self::assertEquals($competition->getPhases(), $competition->getChildren()); |
|
|
|
|
|
|
79
|
|
|
$competition->getPhases()->set($phase->getPhaseNumber(), $phase); |
|
80
|
|
|
self::assertEquals(1, $competition->getPhases()->count()); |
|
81
|
|
|
self::assertEquals($phase, $competition->getPhases()[1]); |
|
82
|
|
|
self::assertEquals($competition->getPhases(), $competition->getChildren()); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Competition::getTeams |
|
87
|
|
|
* @uses \Tfboe\FmLib\Entity\Traits\Competition::init |
|
88
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
|
89
|
|
|
* @uses \Tfboe\FmLib\Entity\Team |
|
90
|
|
|
*/ |
|
91
|
|
|
public function testTeams() |
|
92
|
|
|
{ |
|
93
|
|
|
$competition = $this->competition(); |
|
94
|
|
|
$competition->init(); |
|
|
|
|
|
|
95
|
|
|
$team = new Team(); |
|
96
|
|
|
$team->setStartNumber(1); |
|
97
|
|
|
$competition->getTeams()->set($team->getStartNumber(), $team); |
|
|
|
|
|
|
98
|
|
|
self::assertEquals(1, $competition->getTeams()->count()); |
|
99
|
|
|
self::assertEquals($team, $competition->getTeams()[1]); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Competition::setTournament() |
|
104
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Competition::getTournament() |
|
105
|
|
|
* @covers \Tfboe\FmLib\Entity\Traits\Competition::getParent() |
|
106
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\TournamentHierarchyEntity::__construct |
|
107
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\NameEntity::getName |
|
108
|
|
|
* @uses \Tfboe\FmLib\Entity\Helpers\NameEntity::setName |
|
109
|
|
|
*/ |
|
110
|
|
View Code Duplication |
public function testTournamentAndParent() |
|
|
|
|
|
|
111
|
|
|
{ |
|
112
|
|
|
$competition = $this->competition(); |
|
113
|
|
|
$tournament = $this->createMock(TournamentInterface::class); |
|
114
|
|
|
$competitions = new ArrayCollection(); |
|
115
|
|
|
$tournament->method('getCompetitions')->willReturn($competitions); |
|
116
|
|
|
$competition->setName('test competition'); |
|
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
/** @var TournamentInterface $tournament */ |
|
119
|
|
|
$competition->setTournament($tournament); |
|
|
|
|
|
|
120
|
|
|
self::assertEquals($tournament, $competition->getTournament()); |
|
|
|
|
|
|
121
|
|
|
self::assertEquals($competition->getTournament(), $competition->getParent()); |
|
|
|
|
|
|
122
|
|
|
self::assertEquals(1, $competition->getTournament()->getCompetitions()->count()); |
|
123
|
|
|
self::assertEquals($competition, $competition->getTournament()->getCompetitions()[$competition->getName()]); |
|
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
$tournament2 = $this->createMock(TournamentInterface::class); |
|
126
|
|
|
$competitions2 = new ArrayCollection(); |
|
127
|
|
|
$tournament2->method('getCompetitions')->willReturn($competitions2); |
|
128
|
|
|
/** @var TournamentInterface $tournament2 */ |
|
129
|
|
|
$competition->setTournament($tournament2); |
|
130
|
|
|
|
|
131
|
|
|
self::assertEquals($tournament2, $competition->getTournament()); |
|
132
|
|
|
self::assertEquals($competition->getTournament(), $competition->getParent()); |
|
133
|
|
|
self::assertEquals(1, $competition->getTournament()->getCompetitions()->count()); |
|
134
|
|
|
self::assertEquals(0, $tournament->getCompetitions()->count()); |
|
135
|
|
|
self::assertEquals($competition, $competition->getTournament()->getCompetitions()[$competition->getName()]); |
|
136
|
|
|
} |
|
137
|
|
|
//</editor-fold desc="Public Methods"> |
|
138
|
|
|
|
|
139
|
|
|
//<editor-fold desc="Private Methods"> |
|
140
|
|
|
/** |
|
141
|
|
|
* @return Competition|MockObject a new competition |
|
142
|
|
|
*/ |
|
143
|
|
|
private function competition(): MockObject |
|
144
|
|
|
{ |
|
145
|
|
|
return $this->getMockForTrait(Competition::class); |
|
146
|
|
|
} |
|
147
|
|
|
//</editor-fold desc="Private Methods"> |
|
148
|
|
|
} |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: