1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
8
|
|
|
use Doctrine\Common\Collections\Collection; |
9
|
|
|
use Doctrine\ORM\Annotation as ORM; |
10
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
11
|
|
|
|
12
|
|
|
class GH7062Test extends OrmFunctionalTestCase |
13
|
|
|
{ |
14
|
|
|
private const SEASON_ID = 'season_18'; |
15
|
|
|
private const TEAM_ID = 'team_A'; |
16
|
|
|
|
17
|
|
|
protected function setUp() : void |
18
|
|
|
{ |
19
|
|
|
parent::setUp(); |
20
|
|
|
|
21
|
|
|
$this->setUpEntitySchema( |
22
|
|
|
[ |
23
|
|
|
GH7062Team::class, |
24
|
|
|
GH7062Season::class, |
25
|
|
|
GH7062Ranking::class, |
26
|
|
|
GH7062RankingPosition::class, |
27
|
|
|
] |
28
|
|
|
); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @group 7062 |
33
|
|
|
*/ |
34
|
|
|
public function testEntityWithAssociationKeyIdentityCanBeUpdated() : void |
35
|
|
|
{ |
36
|
|
|
$this->createInitialRankingWithRelatedEntities(); |
37
|
|
|
$this->modifyRanking(); |
38
|
|
|
$this->verifyRanking(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
private function createInitialRankingWithRelatedEntities() : void |
42
|
|
|
{ |
43
|
|
|
$team = new GH7062Team(self::TEAM_ID); |
44
|
|
|
$season = new GH7062Season(self::SEASON_ID); |
45
|
|
|
|
46
|
|
|
$season->ranking = new GH7062Ranking($season, [$team]); |
47
|
|
|
|
48
|
|
|
$this->em->persist($team); |
49
|
|
|
$this->em->persist($season); |
50
|
|
|
$this->em->flush(); |
51
|
|
|
$this->em->clear(); |
52
|
|
|
|
53
|
|
|
foreach ($season->ranking->positions as $position) { |
54
|
|
|
self::assertSame(0, $position->points); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
private function modifyRanking() : void |
59
|
|
|
{ |
60
|
|
|
/** @var GH7062Ranking $ranking */ |
61
|
|
|
$ranking = $this->em->find(GH7062Ranking::class, self::SEASON_ID); |
62
|
|
|
|
63
|
|
|
foreach ($ranking->positions as $position) { |
64
|
|
|
$position->points += 3; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$this->em->flush(); |
68
|
|
|
$this->em->clear(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
private function verifyRanking() : void |
72
|
|
|
{ |
73
|
|
|
/** @var GH7062Season $season */ |
74
|
|
|
$season = $this->em->find(GH7062Season::class, self::SEASON_ID); |
75
|
|
|
self::assertInstanceOf(GH7062Season::class, $season); |
76
|
|
|
|
77
|
|
|
$ranking = $season->ranking; |
78
|
|
|
self::assertInstanceOf(GH7062Ranking::class, $ranking); |
79
|
|
|
|
80
|
|
|
foreach ($ranking->positions as $position) { |
81
|
|
|
self::assertSame(3, $position->points); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Simple Entity whose identity is defined through another Entity (Season) |
88
|
|
|
* |
89
|
|
|
* @ORM\Entity |
90
|
|
|
* @ORM\Table(name="soccer_rankings") |
91
|
|
|
*/ |
92
|
|
|
class GH7062Ranking |
93
|
|
|
{ |
94
|
|
|
/** |
95
|
|
|
* @ORM\Id |
96
|
|
|
* @ORM\OneToOne(targetEntity=GH7062Season::class, inversedBy="ranking") |
97
|
|
|
* @ORM\JoinColumn(name="season", referencedColumnName="id") |
98
|
|
|
* |
99
|
|
|
* @var GH7062Season |
100
|
|
|
*/ |
101
|
|
|
public $season; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @ORM\OneToMany(targetEntity=GH7062RankingPosition::class, mappedBy="ranking", cascade={"all"}) |
105
|
|
|
* |
106
|
|
|
* @var Collection|GH7062RankingPosition[] |
107
|
|
|
*/ |
108
|
|
|
public $positions; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param GH7062Team[] $teams |
112
|
|
|
*/ |
113
|
|
|
public function __construct(GH7062Season $season, array $teams) |
114
|
|
|
{ |
115
|
|
|
$this->season = $season; |
116
|
|
|
$this->positions = new ArrayCollection(); |
117
|
|
|
|
118
|
|
|
foreach ($teams as $team) { |
119
|
|
|
$this->positions[] = new GH7062RankingPosition($this, $team); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Entity which serves as a identity provider for other entities |
126
|
|
|
* |
127
|
|
|
* @ORM\Entity |
128
|
|
|
* @ORM\Table(name="soccer_seasons") |
129
|
|
|
*/ |
130
|
|
|
class GH7062Season |
131
|
|
|
{ |
132
|
|
|
/** |
133
|
|
|
* @ORM\Id |
134
|
|
|
* @ORM\Column(type="string") |
135
|
|
|
* |
136
|
|
|
* @var string |
137
|
|
|
*/ |
138
|
|
|
public $id; |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @ORM\OneToOne(targetEntity=GH7062Ranking::class, mappedBy="season", cascade={"all"}) |
142
|
|
|
* |
143
|
|
|
* @var GH7062Ranking|null |
144
|
|
|
*/ |
145
|
|
|
public $ranking; |
146
|
|
|
|
147
|
|
|
public function __construct(string $id) |
148
|
|
|
{ |
149
|
|
|
$this->id = $id; |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Entity which serves as a identity provider for other entities |
155
|
|
|
* |
156
|
|
|
* @ORM\Entity |
157
|
|
|
* @ORM\Table(name="soccer_teams") |
158
|
|
|
*/ |
159
|
|
|
class GH7062Team |
160
|
|
|
{ |
161
|
|
|
/** |
162
|
|
|
* @ORM\Id |
163
|
|
|
* @ORM\Column(type="string") |
164
|
|
|
* |
165
|
|
|
* @var string |
166
|
|
|
*/ |
167
|
|
|
public $id; |
168
|
|
|
|
169
|
|
|
public function __construct(string $id) |
170
|
|
|
{ |
171
|
|
|
$this->id = $id; |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Entity whose identity is defined through two other entities |
177
|
|
|
* |
178
|
|
|
* @ORM\Entity |
179
|
|
|
* @ORM\Table(name="soccer_ranking_positions") |
180
|
|
|
*/ |
181
|
|
|
class GH7062RankingPosition |
182
|
|
|
{ |
183
|
|
|
/** |
184
|
|
|
* @ORM\Id |
185
|
|
|
* @ORM\ManyToOne(targetEntity=GH7062Ranking::class, inversedBy="positions") |
186
|
|
|
* @ORM\JoinColumn(name="season", referencedColumnName="season") |
187
|
|
|
* |
188
|
|
|
* @var GH7062Ranking |
189
|
|
|
*/ |
190
|
|
|
public $ranking; |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @ORM\Id |
194
|
|
|
* @ORM\ManyToOne(targetEntity=GH7062Team::class) |
195
|
|
|
* @ORM\JoinColumn(name="team_id", referencedColumnName="id") |
196
|
|
|
* |
197
|
|
|
* @var GH7062Team |
198
|
|
|
*/ |
199
|
|
|
public $team; |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @ORM\Column(type="integer") |
203
|
|
|
* |
204
|
|
|
* @var int |
205
|
|
|
*/ |
206
|
|
|
public $points; |
207
|
|
|
|
208
|
|
|
public function __construct(GH7062Ranking $ranking, GH7062Team $team) |
209
|
|
|
{ |
210
|
|
|
$this->ranking = $ranking; |
211
|
|
|
$this->team = $team; |
212
|
|
|
$this->points = 0; |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
|