public function testLazyLoadedEntitiesAreManagedForRemoval() { $this->clearDb(); $michal = new User('michal'); $daniela = new User('daniela'); $city = new City('London'); $michal->setCity($city); $daniela->setCity($city); $this->em->persist($city); $this->em->persist($michal); $this->em->persist($daniela); $this->em->flush(); $this->assertGraphExist('(m:User {login:"******"})-[:LIVES_IN {since:123}]->(c:City {name:"London"})<-[:LIVES_IN {since:123}]-(d:User {login:"******"})'); $this->em->clear(); /** @var City $london */ $london = $this->em->getRepository(City::class)->findOneBy('name', 'London'); $this->assertInstanceOf(LazyRelationshipCollection::class, $london->getHabitants()); $this->assertCount(2, $london->getHabitants()); /** @var LivesIn $livesIn */ foreach ($london->getHabitants() as $livesIn) { $this->assertInstanceOf(User::class, $livesIn->getUser()); $this->assertInstanceOf(City::class, $livesIn->getCity()); $this->assertEquals(123, $livesIn->getSince()); $this->assertInstanceOf(LivesIn::class, $livesIn->getUser()->getLivesIn()); } $u = $london->getHabitants()[0]; $london->getHabitants()->removeElement($u); $u->getUser()->removeCity($u->getCity()); $this->em->flush(); }
/** * @group order-re-prop-lazy */ public function testOrderByRelationshipEntityPropertiesLazyLoaded() { $this->clearDb(); $a = new User('ikwattro'); $b = new User('jexp'); $c = new User('luanne'); $city = new City('London'); $a->setCity($city, 456790); $b->setCity($city, 456789); $c->setCity($city, 456791); $this->em->persist($city); $this->em->flush(); $this->em->clear(); /** @var City $city */ $city = $this->em->getRepository(City::class)->findOneBy('name', 'London'); $this->assertCount(3, $city->getHabitants()); $this->assertEquals(456789, $city->getHabitants()[2]->getSince()); $this->assertEquals(456790, $city->getHabitants()[1]->getSince()); $this->assertEquals(456791, $city->getHabitants()[0]->getSince()); }