Failed Conditions
Pull Request — develop (#6873)
by
unknown
112:44 queued 47:41
created

loadFixturesPersonWithAddress()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 29
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 17
nc 4
nop 0
dl 0
loc 29
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\ORM\Functional;
6
7
use Doctrine\Tests\Models\Cache\Address;
8
use Doctrine\Tests\Models\Cache\Person;
9
use Doctrine\Tests\OrmFunctionalTestCase;
10
11
use Doctrine\Tests\Models\Cache\Country;
12
use Doctrine\Tests\Models\Cache\State;
13
use Doctrine\Tests\Models\Cache\City;
14
15
use Doctrine\Tests\Models\Cache\TravelerProfileInfo;
16
use Doctrine\Tests\Models\Cache\TravelerProfile;
17
use Doctrine\Tests\Models\Cache\Traveler;
18
use Doctrine\Tests\Models\Cache\Travel;
19
20
use Doctrine\Tests\Models\Cache\Restaurant;
21
use Doctrine\Tests\Models\Cache\Beach;
22
use Doctrine\Tests\Models\Cache\Bar;
23
24
use Doctrine\Tests\Models\Cache\AttractionContactInfo;
25
use Doctrine\Tests\Models\Cache\AttractionLocationInfo;
26
27
/**
28
 * @group DDC-2183
29
 */
30
abstract class SecondLevelCacheAbstractTest extends OrmFunctionalTestCase
31
{
32
    protected $people               = [];
33
    protected $addresses            = [];
34
    protected $countries            = [];
35
    protected $states               = [];
36
    protected $cities               = [];
37
    protected $travels              = [];
38
    protected $travelers            = [];
39
    protected $attractions          = [];
40
    protected $attractionsInfo      = [];
41
    protected $travelersWithProfile = [];
42
43
    /**
44
     * @var \Doctrine\ORM\Cache
45
     */
46
    protected $cache;
47
48
    protected function setUp()
49
    {
50
        $this->enableSecondLevelCache();
51
52
        $this->useModelSet('cache');
53
54
        parent::setUp();
55
56
        $this->cache = $this->em->getCache();
57
    }
58
59
    protected function loadFixturesCountries()
60
    {
61
        $brazil  = new Country("Brazil");
62
        $germany = new Country("Germany");
63
64
        $this->countries[] = $brazil;
65
        $this->countries[] = $germany;
66
67
        $this->em->persist($brazil);
68
        $this->em->persist($germany);
69
        $this->em->flush();
70
    }
71
72
    protected function loadFixturesStates()
73
    {
74
        $saopaulo   = new State("São Paulo", $this->countries[0]);
75
        $rio        = new State("Rio de janeiro", $this->countries[0]);
76
        $berlin     = new State("Berlin", $this->countries[1]);
77
        $bavaria    = new State("Bavaria", $this->countries[1]);
78
79
        $this->states[] = $saopaulo;
80
        $this->states[] = $rio;
81
        $this->states[] = $bavaria;
82
        $this->states[] = $berlin;
83
84
        $this->em->persist($saopaulo);
85
        $this->em->persist($rio);
86
        $this->em->persist($bavaria);
87
        $this->em->persist($berlin);
88
89
        $this->em->flush();
90
    }
91
92
    protected function loadFixturesCities()
93
    {
94
        $saopaulo   = new City("São Paulo", $this->states[0]);
95
        $rio        = new City("Rio de janeiro", $this->states[0]);
96
        $berlin     = new City("Berlin", $this->states[1]);
97
        $munich     = new City("Munich", $this->states[1]);
98
99
        $this->states[0]->addCity($saopaulo);
100
        $this->states[0]->addCity($rio);
101
        $this->states[1]->addCity($berlin);
102
        $this->states[1]->addCity($berlin);
103
104
        $this->cities[] = $saopaulo;
105
        $this->cities[] = $rio;
106
        $this->cities[] = $munich;
107
        $this->cities[] = $berlin;
108
109
        $this->em->persist($saopaulo);
110
        $this->em->persist($rio);
111
        $this->em->persist($munich);
112
        $this->em->persist($berlin);
113
114
        $this->em->flush();
115
    }
116
117
    protected function loadFixturesTraveler()
118
    {
119
        $t1   = new Traveler("Fabio Silva");
120
        $t2   = new Traveler("Doctrine Bot");
121
122
        $this->em->persist($t1);
123
        $this->em->persist($t2);
124
125
        $this->travelers[] = $t1;
126
        $this->travelers[] = $t2;
127
128
        $this->em->flush();
129
    }
130
131
    protected function loadFixturesTravelersWithProfile()
132
    {
133
        $t1   = new Traveler("Test traveler 1");
134
        $t2   = new Traveler("Test traveler 2");
135
        $p1   = new TravelerProfile("First Traveler Profile");
136
        $p2   = new TravelerProfile("Second Traveler Profile");
137
138
        $t1->setProfile($p1);
139
        $t2->setProfile($p2);
140
141
        $this->em->persist($p1);
142
        $this->em->persist($p2);
143
        $this->em->persist($t1);
144
        $this->em->persist($t2);
145
146
        $this->travelersWithProfile[] = $t1;
147
        $this->travelersWithProfile[] = $t2;
148
149
        $this->em->flush();
150
    }
151
152
    protected function loadFixturesTravelersProfileInfo()
153
    {
154
        $p1   = $this->travelersWithProfile[0]->getProfile();
155
        $p2   = $this->travelersWithProfile[1]->getProfile();
156
        $i1   = new TravelerProfileInfo($p1, "First Profile Info ...");
157
        $i2   = new TravelerProfileInfo($p2, "Second  Profile Info ...");
158
159
        $p1->setInfo($i1);
160
        $p2->setInfo($i2);
161
162
        $this->em->persist($i1);
163
        $this->em->persist($i2);
164
        $this->em->persist($p1);
165
        $this->em->persist($p2);
166
167
        $this->em->flush();
168
    }
169
170
    protected function loadFixturesTravels()
171
    {
172
        $t1   = new Travel($this->travelers[0]);
173
        $t2   = new Travel($this->travelers[1]);
174
        $t3   = new Travel($this->travelers[1]);
175
176
        $t1->addVisitedCity($this->cities[0]);
177
        $t1->addVisitedCity($this->cities[1]);
178
        $t1->addVisitedCity($this->cities[2]);
179
180
        $t2->addVisitedCity($this->cities[1]);
181
        $t2->addVisitedCity($this->cities[3]);
182
183
        $this->em->persist($t1);
184
        $this->em->persist($t2);
185
        $this->em->persist($t3);
186
187
        $this->travels[] = $t1;
188
        $this->travels[] = $t2;
189
        $this->travels[] = $t3;
190
191
        $this->em->flush();
192
    }
193
194
    protected function loadFixturesAttractions()
195
    {
196
        $this->attractions[] = new Bar('Boteco São Bento', $this->cities[0]);
197
        $this->attractions[] = new Bar('Prainha Paulista', $this->cities[0]);
198
        $this->attractions[] = new Beach('Copacabana', $this->cities[1]);
199
        $this->attractions[] = new Beach('Ipanema', $this->cities[1]);
200
        $this->attractions[] = new Bar('Schneider Weisse', $this->cities[2]);
201
        $this->attractions[] = new Restaurant('Reinstoff', $this->cities[3]);
202
        $this->attractions[] = new Restaurant('Fischers Fritz', $this->cities[3]);
203
204
        $this->cities[0]->addAttraction($this->attractions[0]);
205
        $this->cities[0]->addAttraction($this->attractions[1]);
206
        $this->cities[1]->addAttraction($this->attractions[2]);
207
        $this->cities[1]->addAttraction($this->attractions[3]);
208
        $this->cities[2]->addAttraction($this->attractions[4]);
209
        $this->cities[3]->addAttraction($this->attractions[5]);
210
        $this->cities[3]->addAttraction($this->attractions[6]);
211
212
        foreach ($this->attractions as $attraction) {
213
            $this->em->persist($attraction);
214
        }
215
216
        $this->em->flush();
217
    }
218
219
    protected function loadFixturesAttractionsInfo()
220
    {
221
        $this->attractionsInfo[] = new AttractionContactInfo('0000-0000', $this->attractions[0]);
222
        $this->attractionsInfo[] = new AttractionContactInfo('1111-1111', $this->attractions[1]);
223
        $this->attractionsInfo[] = new AttractionLocationInfo('Some St 1', $this->attractions[2]);
224
        $this->attractionsInfo[] = new AttractionLocationInfo('Some St 2', $this->attractions[3]);
225
226
        foreach ($this->attractionsInfo as $info) {
227
            $this->em->persist($info);
228
        }
229
230
        $this->em->flush();
231
    }
232
233
    protected function loadFixturesPersonWithAddress()
234
    {
235
        $person1  = new Person('Guilherme Blanco');
236
        $address1 = new Address('Canada');
237
238
        $person1->address = $address1;
239
        $address1->person = $person1;
240
241
        $person2  = new Person('Marco Pivetta');
242
        $address2 = new Address('Germany');
243
244
        $person2->address = $address2;
245
        $address2->person = $person2;
246
247
        $this->people[] = $person1;
248
        $this->people[] = $person2;
249
250
        $this->addresses[] = $address1;
251
        $this->addresses[] = $address2;
252
253
        foreach ($this->people as $person) {
254
            $this->em->persist($person);
255
        }
256
257
        foreach ($this->addresses as $address) {
258
            $this->em->persist($address);
259
        }
260
261
        $this->em->flush();
262
    }
263
264
    protected function getEntityRegion($className)
265
    {
266
        return $this->cache->getEntityCacheRegion($className)->getName();
267
    }
268
269
    protected function getCollectionRegion($className, $association)
270
    {
271
        return $this->cache->getCollectionCacheRegion($className, $association)->getName();
272
    }
273
274
    protected function getDefaultQueryRegionName()
275
    {
276
        return $this->cache->getQueryCache()->getRegion()->getName();
277
    }
278
279
    protected function evictRegions()
280
    {
281
        $this->cache->evictQueryRegions();
282
        $this->cache->evictEntityRegions();
283
        $this->cache->evictCollectionRegions();
284
    }
285
}
286