@@ -16,70 +16,70 @@ discard block |
||
16 | 16 | */ |
17 | 17 | class DDC6470Test extends \Doctrine\Tests\OrmFunctionalTestCase |
18 | 18 | { |
19 | - public function setUp() |
|
20 | - { |
|
21 | - $this->enableSecondLevelCache(); |
|
22 | - parent::setUp(); |
|
23 | - |
|
24 | - try { |
|
25 | - $this->setUpEntitySchema([ |
|
26 | - DDC6470Source::class, |
|
27 | - DDC6470Target1::class, |
|
28 | - DDC6470Target2::class, |
|
29 | - ]); |
|
30 | - } catch (SchemaException $e) { |
|
31 | - } |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * @throws \Doctrine\Common\Persistence\Mapping\MappingException |
|
36 | - * @throws \Doctrine\ORM\ORMException |
|
37 | - * @throws \Doctrine\ORM\OptimisticLockException |
|
38 | - */ |
|
39 | - public function testOneToOne() |
|
40 | - { |
|
41 | - $source1 = new DDC6470Source(); |
|
42 | - $target1 = new DDC6470Target1(); |
|
43 | - $source1->setTarget1($target1); |
|
44 | - |
|
45 | - $source2 = new DDC6470Source(); |
|
46 | - $target2 = new DDC6470Target2(); |
|
47 | - $source2->setTarget2($target2); |
|
48 | - |
|
49 | - $this->_em->persist($source1); |
|
50 | - $this->_em->persist($source2); |
|
51 | - $this->_em->flush(); |
|
52 | - $this->_em->clear(); |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - $this->assertTrue($this->_em->getCache()->containsEntity(DDC6470Source::class, ['id' => $source1->getId()])); |
|
57 | - $this->assertTrue($this->_em->getCache()->containsEntity(DDC6470Source::class, ['id' => $source2->getId()])); |
|
58 | - $this->assertTrue($this->_em->getCache()->containsEntity(DDC6470Target1::class, ['id' => $target1->getId()])); |
|
59 | - $this->assertTrue($this->_em->getCache()->containsEntity(DDC6470Target1::class, ['id' => $target2->getId()])); |
|
60 | - |
|
61 | - |
|
62 | - $queryCount = $this->getCurrentQueryCount(); |
|
63 | - |
|
64 | - /** @var EntityRepository $er */ |
|
65 | - $er = $this->_em->getRepository(DDC6470Source::class); |
|
66 | - $qb = $er->createQueryBuilder("n"); |
|
67 | - $qb->setCacheable(true)->setLifetime(3 * 60)->setCacheRegion($region = time()); |
|
68 | - |
|
69 | - $qb->getQuery()->getResult(); |
|
70 | - |
|
71 | - $newQueryCount = $this->getCurrentQueryCount(); |
|
72 | - $this->assertEquals($queryCount + 1, $newQueryCount, "One for query only. One more appears here @see UnitOfWork:2654."); |
|
73 | - |
|
74 | - $this->_em->clear(); |
|
75 | - |
|
76 | - /** @var EntityRepository $er */ |
|
77 | - $er = $this->_em->getRepository(DDC6470Source::class); |
|
78 | - $qb = $er->createQueryBuilder("n"); |
|
79 | - $qb->setCacheable(true)->setLifetime(3 * 60)->setCacheRegion($region); |
|
80 | - $qb->getQuery()->getResult(); |
|
81 | - $this->assertEquals($newQueryCount, $this->getCurrentQueryCount(), "Assert everything get from cache."); |
|
82 | - } |
|
19 | + public function setUp() |
|
20 | + { |
|
21 | + $this->enableSecondLevelCache(); |
|
22 | + parent::setUp(); |
|
23 | + |
|
24 | + try { |
|
25 | + $this->setUpEntitySchema([ |
|
26 | + DDC6470Source::class, |
|
27 | + DDC6470Target1::class, |
|
28 | + DDC6470Target2::class, |
|
29 | + ]); |
|
30 | + } catch (SchemaException $e) { |
|
31 | + } |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * @throws \Doctrine\Common\Persistence\Mapping\MappingException |
|
36 | + * @throws \Doctrine\ORM\ORMException |
|
37 | + * @throws \Doctrine\ORM\OptimisticLockException |
|
38 | + */ |
|
39 | + public function testOneToOne() |
|
40 | + { |
|
41 | + $source1 = new DDC6470Source(); |
|
42 | + $target1 = new DDC6470Target1(); |
|
43 | + $source1->setTarget1($target1); |
|
44 | + |
|
45 | + $source2 = new DDC6470Source(); |
|
46 | + $target2 = new DDC6470Target2(); |
|
47 | + $source2->setTarget2($target2); |
|
48 | + |
|
49 | + $this->_em->persist($source1); |
|
50 | + $this->_em->persist($source2); |
|
51 | + $this->_em->flush(); |
|
52 | + $this->_em->clear(); |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + $this->assertTrue($this->_em->getCache()->containsEntity(DDC6470Source::class, ['id' => $source1->getId()])); |
|
57 | + $this->assertTrue($this->_em->getCache()->containsEntity(DDC6470Source::class, ['id' => $source2->getId()])); |
|
58 | + $this->assertTrue($this->_em->getCache()->containsEntity(DDC6470Target1::class, ['id' => $target1->getId()])); |
|
59 | + $this->assertTrue($this->_em->getCache()->containsEntity(DDC6470Target1::class, ['id' => $target2->getId()])); |
|
60 | + |
|
61 | + |
|
62 | + $queryCount = $this->getCurrentQueryCount(); |
|
63 | + |
|
64 | + /** @var EntityRepository $er */ |
|
65 | + $er = $this->_em->getRepository(DDC6470Source::class); |
|
66 | + $qb = $er->createQueryBuilder("n"); |
|
67 | + $qb->setCacheable(true)->setLifetime(3 * 60)->setCacheRegion($region = time()); |
|
68 | + |
|
69 | + $qb->getQuery()->getResult(); |
|
70 | + |
|
71 | + $newQueryCount = $this->getCurrentQueryCount(); |
|
72 | + $this->assertEquals($queryCount + 1, $newQueryCount, "One for query only. One more appears here @see UnitOfWork:2654."); |
|
73 | + |
|
74 | + $this->_em->clear(); |
|
75 | + |
|
76 | + /** @var EntityRepository $er */ |
|
77 | + $er = $this->_em->getRepository(DDC6470Source::class); |
|
78 | + $qb = $er->createQueryBuilder("n"); |
|
79 | + $qb->setCacheable(true)->setLifetime(3 * 60)->setCacheRegion($region); |
|
80 | + $qb->getQuery()->getResult(); |
|
81 | + $this->assertEquals($newQueryCount, $this->getCurrentQueryCount(), "Assert everything get from cache."); |
|
82 | + } |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -88,82 +88,82 @@ discard block |
||
88 | 88 | */ |
89 | 89 | class DDC6470Source |
90 | 90 | { |
91 | - /** |
|
92 | - * @Id |
|
93 | - * @GeneratedValue() |
|
94 | - * @Column(type="integer") |
|
95 | - * @var int |
|
96 | - */ |
|
97 | - protected $id; |
|
98 | - /** |
|
99 | - * @Cache("NONSTRICT_READ_WRITE") |
|
100 | - * @OneToOne(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\DDC6470Target1", mappedBy="source", cascade={"persist"}) |
|
101 | - * @var DDC6470Target1 |
|
102 | - */ |
|
103 | - protected $target1; |
|
104 | - /** |
|
105 | - * @Cache("NONSTRICT_READ_WRITE") |
|
106 | - * @OneToOne(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\DDC6470Target2", mappedBy="source", cascade={"persist"}) |
|
107 | - * @var DDC6470Target2 |
|
108 | - */ |
|
109 | - protected $target2; |
|
110 | - |
|
111 | - /** |
|
112 | - * @return int |
|
113 | - */ |
|
114 | - public function getId(): ?int |
|
115 | - { |
|
116 | - return $this->id; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @param int $id |
|
121 | - * @return DDC6470Source |
|
122 | - */ |
|
123 | - public function setId(?int $id): DDC6470Source |
|
124 | - { |
|
125 | - $this->id = $id; |
|
126 | - |
|
127 | - return $this; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @return DDC6470Target1 |
|
132 | - */ |
|
133 | - public function getTarget1(): ?DDC6470Target1 |
|
134 | - { |
|
135 | - return $this->target1; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * @param DDC6470Target1 $target |
|
140 | - * @return DDC6470Source |
|
141 | - */ |
|
142 | - public function setTarget1(?DDC6470Target1 $target): DDC6470Source |
|
143 | - { |
|
144 | - $this->target1 = $target; |
|
145 | - |
|
146 | - return $this; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * @return DDC6470Target2 |
|
151 | - */ |
|
152 | - public function getTarget2(): ?DDC6470Target2 |
|
153 | - { |
|
154 | - return $this->target2; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * @param DDC6470Target2 $target2 |
|
159 | - * @return DDC6470Source |
|
160 | - */ |
|
161 | - public function setTarget2(?DDC6470Target2 $target2): DDC6470Source |
|
162 | - { |
|
163 | - $this->target2 = $target2; |
|
164 | - |
|
165 | - return $this; |
|
166 | - } |
|
91 | + /** |
|
92 | + * @Id |
|
93 | + * @GeneratedValue() |
|
94 | + * @Column(type="integer") |
|
95 | + * @var int |
|
96 | + */ |
|
97 | + protected $id; |
|
98 | + /** |
|
99 | + * @Cache("NONSTRICT_READ_WRITE") |
|
100 | + * @OneToOne(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\DDC6470Target1", mappedBy="source", cascade={"persist"}) |
|
101 | + * @var DDC6470Target1 |
|
102 | + */ |
|
103 | + protected $target1; |
|
104 | + /** |
|
105 | + * @Cache("NONSTRICT_READ_WRITE") |
|
106 | + * @OneToOne(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\DDC6470Target2", mappedBy="source", cascade={"persist"}) |
|
107 | + * @var DDC6470Target2 |
|
108 | + */ |
|
109 | + protected $target2; |
|
110 | + |
|
111 | + /** |
|
112 | + * @return int |
|
113 | + */ |
|
114 | + public function getId(): ?int |
|
115 | + { |
|
116 | + return $this->id; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @param int $id |
|
121 | + * @return DDC6470Source |
|
122 | + */ |
|
123 | + public function setId(?int $id): DDC6470Source |
|
124 | + { |
|
125 | + $this->id = $id; |
|
126 | + |
|
127 | + return $this; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @return DDC6470Target1 |
|
132 | + */ |
|
133 | + public function getTarget1(): ?DDC6470Target1 |
|
134 | + { |
|
135 | + return $this->target1; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * @param DDC6470Target1 $target |
|
140 | + * @return DDC6470Source |
|
141 | + */ |
|
142 | + public function setTarget1(?DDC6470Target1 $target): DDC6470Source |
|
143 | + { |
|
144 | + $this->target1 = $target; |
|
145 | + |
|
146 | + return $this; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * @return DDC6470Target2 |
|
151 | + */ |
|
152 | + public function getTarget2(): ?DDC6470Target2 |
|
153 | + { |
|
154 | + return $this->target2; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * @param DDC6470Target2 $target2 |
|
159 | + * @return DDC6470Source |
|
160 | + */ |
|
161 | + public function setTarget2(?DDC6470Target2 $target2): DDC6470Source |
|
162 | + { |
|
163 | + $this->target2 = $target2; |
|
164 | + |
|
165 | + return $this; |
|
166 | + } |
|
167 | 167 | |
168 | 168 | } |
169 | 169 | |
@@ -173,57 +173,57 @@ discard block |
||
173 | 173 | */ |
174 | 174 | class DDC6470Target1 |
175 | 175 | { |
176 | - /** |
|
177 | - * @Id |
|
178 | - * @GeneratedValue() |
|
179 | - * @Column(type="integer") |
|
180 | - * @var int |
|
181 | - */ |
|
182 | - protected $id; |
|
183 | - /** |
|
184 | - * @Cache("NONSTRICT_READ_WRITE") |
|
185 | - * @OneToOne(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\DDC6470Source", inversedBy="target1") |
|
186 | - * @var DDC6470Source |
|
187 | - */ |
|
188 | - protected $source; |
|
189 | - |
|
190 | - /** |
|
191 | - * @return int |
|
192 | - */ |
|
193 | - public function getId(): ?int |
|
194 | - { |
|
195 | - return $this->id; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * @param int $id |
|
200 | - * @return DDC6470Target1 |
|
201 | - */ |
|
202 | - public function setId(?int $id): DDC6470Target1 |
|
203 | - { |
|
204 | - $this->id = $id; |
|
205 | - |
|
206 | - return $this; |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * @return DDC6470Source |
|
211 | - */ |
|
212 | - public function getSource(): ?DDC6470Source |
|
213 | - { |
|
214 | - return $this->source; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * @param DDC6470Source $source |
|
219 | - * @return DDC6470Target1 |
|
220 | - */ |
|
221 | - public function setSource(?DDC6470Source $source): DDC6470Target1 |
|
222 | - { |
|
223 | - $this->source = $source; |
|
224 | - |
|
225 | - return $this; |
|
226 | - } |
|
176 | + /** |
|
177 | + * @Id |
|
178 | + * @GeneratedValue() |
|
179 | + * @Column(type="integer") |
|
180 | + * @var int |
|
181 | + */ |
|
182 | + protected $id; |
|
183 | + /** |
|
184 | + * @Cache("NONSTRICT_READ_WRITE") |
|
185 | + * @OneToOne(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\DDC6470Source", inversedBy="target1") |
|
186 | + * @var DDC6470Source |
|
187 | + */ |
|
188 | + protected $source; |
|
189 | + |
|
190 | + /** |
|
191 | + * @return int |
|
192 | + */ |
|
193 | + public function getId(): ?int |
|
194 | + { |
|
195 | + return $this->id; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * @param int $id |
|
200 | + * @return DDC6470Target1 |
|
201 | + */ |
|
202 | + public function setId(?int $id): DDC6470Target1 |
|
203 | + { |
|
204 | + $this->id = $id; |
|
205 | + |
|
206 | + return $this; |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * @return DDC6470Source |
|
211 | + */ |
|
212 | + public function getSource(): ?DDC6470Source |
|
213 | + { |
|
214 | + return $this->source; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * @param DDC6470Source $source |
|
219 | + * @return DDC6470Target1 |
|
220 | + */ |
|
221 | + public function setSource(?DDC6470Source $source): DDC6470Target1 |
|
222 | + { |
|
223 | + $this->source = $source; |
|
224 | + |
|
225 | + return $this; |
|
226 | + } |
|
227 | 227 | |
228 | 228 | } |
229 | 229 | |
@@ -233,56 +233,56 @@ discard block |
||
233 | 233 | */ |
234 | 234 | class DDC6470Target2 |
235 | 235 | { |
236 | - /** |
|
237 | - * @Id |
|
238 | - * @GeneratedValue() |
|
239 | - * @Column(type="integer") |
|
240 | - * @var int |
|
241 | - */ |
|
242 | - protected $id; |
|
243 | - /** |
|
244 | - * @Cache("NONSTRICT_READ_WRITE") |
|
245 | - * @OneToOne(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\DDC6470Source", inversedBy="target2") |
|
246 | - * @var DDC6470Source |
|
247 | - */ |
|
248 | - protected $source; |
|
249 | - |
|
250 | - /** |
|
251 | - * @return int |
|
252 | - */ |
|
253 | - public function getId(): ?int |
|
254 | - { |
|
255 | - return $this->id; |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * @param int $id |
|
260 | - * @return DDC6470Target2 |
|
261 | - */ |
|
262 | - public function setId(?int $id): DDC6470Target2 |
|
263 | - { |
|
264 | - $this->id = $id; |
|
265 | - |
|
266 | - return $this; |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * @return DDC6470Source |
|
271 | - */ |
|
272 | - public function getSource(): ?DDC6470Source |
|
273 | - { |
|
274 | - return $this->source; |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * @param DDC6470Source $source |
|
279 | - * @return DDC6470Target2 |
|
280 | - */ |
|
281 | - public function setSource(?DDC6470Source $source): DDC6470Target2 |
|
282 | - { |
|
283 | - $this->source = $source; |
|
284 | - |
|
285 | - return $this; |
|
286 | - } |
|
236 | + /** |
|
237 | + * @Id |
|
238 | + * @GeneratedValue() |
|
239 | + * @Column(type="integer") |
|
240 | + * @var int |
|
241 | + */ |
|
242 | + protected $id; |
|
243 | + /** |
|
244 | + * @Cache("NONSTRICT_READ_WRITE") |
|
245 | + * @OneToOne(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\DDC6470Source", inversedBy="target2") |
|
246 | + * @var DDC6470Source |
|
247 | + */ |
|
248 | + protected $source; |
|
249 | + |
|
250 | + /** |
|
251 | + * @return int |
|
252 | + */ |
|
253 | + public function getId(): ?int |
|
254 | + { |
|
255 | + return $this->id; |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * @param int $id |
|
260 | + * @return DDC6470Target2 |
|
261 | + */ |
|
262 | + public function setId(?int $id): DDC6470Target2 |
|
263 | + { |
|
264 | + $this->id = $id; |
|
265 | + |
|
266 | + return $this; |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * @return DDC6470Source |
|
271 | + */ |
|
272 | + public function getSource(): ?DDC6470Source |
|
273 | + { |
|
274 | + return $this->source; |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * @param DDC6470Source $source |
|
279 | + * @return DDC6470Target2 |
|
280 | + */ |
|
281 | + public function setSource(?DDC6470Source $source): DDC6470Target2 |
|
282 | + { |
|
283 | + $this->source = $source; |
|
284 | + |
|
285 | + return $this; |
|
286 | + } |
|
287 | 287 | |
288 | 288 | } |