@@ 279-322 (lines=44) @@ | ||
276 | /** |
|
277 | * @group DDC-546 |
|
278 | */ |
|
279 | public function testContainsOneToMany() |
|
280 | { |
|
281 | $user = $this->em->find(CmsUser::class, $this->userId); |
|
282 | self::assertFalse($user->articles->isInitialized(), "Pre-Condition: Collection is not initialized."); |
|
283 | ||
284 | // Test One to Many existence retrieved from DB |
|
285 | $article = $this->em->find(CmsArticle::class, $this->articleId); |
|
286 | $queryCount = $this->getCurrentQueryCount(); |
|
287 | ||
288 | self::assertTrue($user->articles->contains($article)); |
|
289 | self::assertFalse($user->articles->isInitialized(), "Post-Condition: Collection is not initialized."); |
|
290 | self::assertEquals($queryCount + 1, $this->getCurrentQueryCount()); |
|
291 | ||
292 | // Test One to Many existence with state new |
|
293 | $article = new CmsArticle(); |
|
294 | $article->topic = "Testnew"; |
|
295 | $article->text = "blub"; |
|
296 | ||
297 | $queryCount = $this->getCurrentQueryCount(); |
|
298 | self::assertFalse($user->articles->contains($article)); |
|
299 | self::assertEquals($queryCount, $this->getCurrentQueryCount(), "Checking for contains of new entity should cause no query to be executed."); |
|
300 | ||
301 | // Test One to Many existence with state clear |
|
302 | $this->em->persist($article); |
|
303 | $this->em->flush(); |
|
304 | ||
305 | $queryCount = $this->getCurrentQueryCount(); |
|
306 | self::assertFalse($user->articles->contains($article)); |
|
307 | self::assertEquals($queryCount+1, $this->getCurrentQueryCount(), "Checking for contains of persisted entity should cause one query to be executed."); |
|
308 | self::assertFalse($user->articles->isInitialized(), "Post-Condition: Collection is not initialized."); |
|
309 | ||
310 | // Test One to Many existence with state managed |
|
311 | $article = new CmsArticle(); |
|
312 | $article->topic = "How to not fail anymore on tests"; |
|
313 | $article->text = "That is simple! Just write more tests!"; |
|
314 | ||
315 | $this->em->persist($article); |
|
316 | ||
317 | $queryCount = $this->getCurrentQueryCount(); |
|
318 | ||
319 | self::assertFalse($user->articles->contains($article)); |
|
320 | self::assertEquals($queryCount, $this->getCurrentQueryCount(), "Checking for contains of managed entity (but not persisted) should cause no query to be executed."); |
|
321 | self::assertFalse($user->articles->isInitialized(), "Post-Condition: Collection is not initialized."); |
|
322 | } |
|
323 | ||
324 | /** |
|
325 | * @group DDC-2504 |
|
@@ 416-460 (lines=45) @@ | ||
413 | /** |
|
414 | * @group DDC-546 |
|
415 | */ |
|
416 | public function testContainsManyToMany() |
|
417 | { |
|
418 | $user = $this->em->find(CmsUser::class, $this->userId); |
|
419 | self::assertFalse($user->groups->isInitialized(), "Pre-Condition: Collection is not initialized."); |
|
420 | ||
421 | // Test Many to Many existence retrieved from DB |
|
422 | $group = $this->em->find(CmsGroup::class, $this->groupId); |
|
423 | $queryCount = $this->getCurrentQueryCount(); |
|
424 | ||
425 | self::assertTrue($user->groups->contains($group)); |
|
426 | self::assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Checking for contains of managed entity should cause one query to be executed."); |
|
427 | self::assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized."); |
|
428 | ||
429 | // Test Many to Many existence with state new |
|
430 | $group = new CmsGroup(); |
|
431 | $group->name = "A New group!"; |
|
432 | ||
433 | $queryCount = $this->getCurrentQueryCount(); |
|
434 | ||
435 | self::assertFalse($user->groups->contains($group)); |
|
436 | self::assertEquals($queryCount, $this->getCurrentQueryCount(), "Checking for contains of new entity should cause no query to be executed."); |
|
437 | self::assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized."); |
|
438 | ||
439 | // Test Many to Many existence with state clear |
|
440 | $this->em->persist($group); |
|
441 | $this->em->flush(); |
|
442 | ||
443 | $queryCount = $this->getCurrentQueryCount(); |
|
444 | ||
445 | self::assertFalse($user->groups->contains($group)); |
|
446 | self::assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Checking for contains of persisted entity should cause one query to be executed."); |
|
447 | self::assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized."); |
|
448 | ||
449 | // Test Many to Many existence with state managed |
|
450 | $group = new CmsGroup(); |
|
451 | $group->name = "My managed group"; |
|
452 | ||
453 | $this->em->persist($group); |
|
454 | ||
455 | $queryCount = $this->getCurrentQueryCount(); |
|
456 | ||
457 | self::assertFalse($user->groups->contains($group)); |
|
458 | self::assertEquals($queryCount, $this->getCurrentQueryCount(), "Checking for contains of managed entity (but not persisted) should cause no query to be executed."); |
|
459 | self::assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized."); |
|
460 | } |
|
461 | ||
462 | /** |
|
463 | * @group DDC-546 |