refresh() public method

This will also convert a fresh entity to an OrmProxyInterface.
public refresh ( object &$entity ) : object
$entity object
return object
Example #1
0
 /**
  * @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);
 }
Example #2
0
 /**
  * @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);
 }
Example #3
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());
 }