/** * @dataProvider entityManagerDataProvider * @param EntityManager $em */ public function testRefs(EntityManager $em) { $members = $em->getDriver()->getMultiValueIndex($em->getKeyScheme()->getEntityRefKey('leaf', 'leaf1')); $this->assertCount(0, $members); $leaf = (new Leaf())->setId('leaf1'); $owner = (new Owner())->setId('owner1')->setLeaf([$leaf]); $em->persist($leaf)->persist($owner)->flush(); $members = $em->getDriver()->getMultiValueIndex($em->getKeyScheme()->getEntityRefKey('leaf', 'leaf1')); $this->assertCount(1, $members); $ref = new Ref(Owner::class, 'owner1', 'leaf'); $this->assertEquals((string) $ref, $members[0]); $leaves = $em->sortedQuery(new SortedQuery($owner, 'leaf', 'id')); $this->assertCount(1, $leaves); $em->refresh($owner); $em->refresh($leaf); $leaf->setPublished(false); $em->persist($leaf)->flush(); $leaves = $em->sortedQuery(new SortedQuery($owner, 'leaf', 'id')); $this->assertCount(0, $leaves); $leaf->setPublished(true); $em->persist($leaf)->flush(); $leaves = $em->sortedQuery(new SortedQuery($owner, 'leaf', 'id')); $this->assertCount(1, $leaves); $em->delete($leaf)->flush(); $leaves = $em->sortedQuery(new SortedQuery($owner, 'leaf', 'id')); $this->assertCount(0, $leaves); }
/** * @dataProvider entityManagerDataProvider * @param EntityManager $em */ public function testRefresh(EntityManager $em) { $product = new Product(); $product->setId(222)->setName('Test Product')->setDescription("lorem ipsum"); $em->persist($product)->flush(); $r = $em->retrieve(Product::class, '222'); $r->setDescription('hello world'); $em->persist($r)->flush(); $this->assertEquals('lorem ipsum', $product->getDescription()); $this->assertFalse($product instanceof OrmProxyInterface); $em->refresh($product); $this->assertEquals('hello world', $product->getDescription()); $this->assertTrue($product instanceof OrmProxyInterface); }
/** * @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()); }