public function testCacheInitializeCollectionWithNewObjects()
 {
     $this->_em->clear();
     $this->evictRegions();
     $traveler = new Traveler("Doctrine Bot");
     for ($i = 0; $i < 3; ++$i) {
         $traveler->getTravels()->add(new Travel($traveler));
     }
     $this->_em->persist($traveler);
     $this->_em->flush();
     $this->_em->clear();
     $this->assertCount(3, $traveler->getTravels());
     $travelerId = $traveler->getId();
     $queryCount = $this->getCurrentQueryCount();
     $entity = $this->_em->find(Traveler::CLASSNAME, $travelerId);
     $this->assertEquals($queryCount, $this->getCurrentQueryCount());
     $this->assertFalse($entity->getTravels()->isInitialized());
     $newItem = new Travel($entity);
     $entity->getTravels()->add($newItem);
     $this->assertFalse($entity->getTravels()->isInitialized());
     $this->assertCount(4, $entity->getTravels());
     $this->assertTrue($entity->getTravels()->isInitialized());
     $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());
     $this->_em->flush();
     $this->_em->clear();
     $query = "SELECT t, tt FROM Doctrine\\Tests\\Models\\Cache\\Traveler t JOIN t.travels tt WHERE t.id = {$travelerId}";
     $result = $this->_em->createQuery($query)->getSingleResult();
     $this->assertEquals(4, $result->getTravels()->count());
 }
 protected function loadFixturesTravelersWithProfile()
 {
     $t1 = new Traveler("Test traveler 1");
     $t2 = new Traveler("Test traveler 2");
     $p1 = new TravelerProfile("First Traveler Profile");
     $p2 = new TravelerProfile("Second Traveler Profile");
     $t1->setProfile($p1);
     $t2->setProfile($p2);
     $this->_em->persist($p1);
     $this->_em->persist($p2);
     $this->_em->persist($t1);
     $this->_em->persist($t2);
     $this->travelersWithProfile[] = $t1;
     $this->travelersWithProfile[] = $t2;
     $this->_em->flush();
 }