Esempio n. 1
0
 /**
  * @dataProvider entityManagerDataProvider
  * @param EntityManager $em
  */
 public function testRelatedIndexDeletion(EntityManager $em)
 {
     $home = new Address();
     $home->setId(44)->setStreet('Oxford St');
     $work = new Address();
     $work->setId(45)->setStreet('George St');
     $user = new User();
     $user->setId(23)->setName('Barry')->setAddress($home);
     $em->persist($user)->persist($home)->persist($work)->flush();
     /** @var User|OrmProxyInterface $user_home */
     $user_home = $em->retrieveByIndex(User::class, 'slug', $user->getId() . '.' . $home->getId());
     $this->assertEquals(23, $user_home->getId());
     $this->assertEquals('Oxford St', $user_home->getAddress()->getStreet());
     $slug = $user_home->getIndexOriginalValue('slug');
     $this->assertEquals('23.44', $slug);
     $user_home->setName('Other Barry');
     $user_home->setAddress($work);
     $em->persist($user_home)->flush();
     /** @var User $user_work */
     $user_work = $em->retrieveByIndex(User::class, 'slug', $user->getId() . '.' . $work->getId());
     $this->assertEquals(23, $user_work->getId());
     $this->assertEquals('George St', $user_work->getAddress()->getStreet());
     $this->setExpectedException(NotFoundException::class);
     $em->retrieveByIndex(User::class, 'slug', $user->getId() . '.' . $home->getId());
 }
Esempio n. 2
0
 /**
  * @dataProvider entityManagerDataProvider
  * @param EntityManager $em
  */
 public function testOneToOneBreaking(EntityManager $em)
 {
     $ed = new User();
     $ed->setId(900)->setName('Ed');
     $jane = new User();
     $jane->setId(901)->setName('Jane');
     $address = new Address();
     $address->setId(951)->setStreet('Howzer-Black St');
     $ed->setAddress($address);
     $em->persist($address)->persist($ed)->persist($jane)->flush();
     $em->refresh($ed);
     $em->refresh($jane);
     $em->refresh($address);
     $jane->setAddress($address);
     $em->persist($jane)->flush();
     $em->refresh($ed);
     $em->refresh($jane);
     $em->refresh($address);
     $this->assertNull($ed->getAddress());
     $this->assertEquals('Howzer-Black St', $jane->getAddress()->getStreet());
     $this->assertEquals('Jane', $address->getUser()->getName());
 }