function testRelationRemovalFromSingleElement() { $movie = new Entity\Movie(); $actor = new Entity\Person(); $actor->setFirstName('Bob'); $movie->setMainActor($actor); $em = $this->getEntityManager(); $em->persist($movie); $em->flush(); $em = $this->getEntityManager(); $movie = $em->find(get_class($movie), $movie->getId()); $replacement = new Entity\Person(); $replacement->setFirstName('Roger'); $movie->setMainActor($replacement); $em->persist($movie); $em->flush(); $em = $this->getEntityManager(); $movie = $em->find(get_class($movie), $movie->getId()); $this->assertEquals('Roger', $movie->getMainActor()->getFirstName()); }
function testManyToOneRelation() { $legolas = new Entity\Person(); $legolas->setFirstName('Orlando'); $legolas->setLastName('Bloom'); $entity = new Entity\Movie(); $entity->setTitle('Return of the king'); $entity->setMainActor($legolas); $em = $this->getEntityManager(); $em->persist($entity); $em->flush(); $em = $this->getEntityManager(); $movie = $em->find(get_class($entity), $entity->getId()); $this->assertEquals('Orlando', $movie->getMainActor()->getFirstName()); }