コード例 #1
0
ファイル: UnitOfWorkTest.php プロジェクト: andreia/doctrine
 public function testChangeTrackingNotify()
 {
     $persister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata("Doctrine\\Tests\\ORM\\NotifyChangedEntity"));
     $this->_unitOfWork->setEntityPersister('Doctrine\\Tests\\ORM\\NotifyChangedEntity', $persister);
     $entity = new NotifyChangedEntity();
     $entity->setData('thedata');
     $this->_unitOfWork->persist($entity);
     $this->_unitOfWork->commit();
     $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity));
     $entity->setData('newdata');
     $this->assertTrue($this->_unitOfWork->isScheduledForUpdate($entity));
     $this->assertEquals(array('data' => array('thedata', 'newdata')), $this->_unitOfWork->getEntityChangeSet($entity));
 }
コード例 #2
0
 public function testChangeTrackingNotify()
 {
     $persister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata("Doctrine\\Tests\\ORM\\NotifyChangedEntity"));
     $this->_unitOfWork->setEntityPersister('Doctrine\\Tests\\ORM\\NotifyChangedEntity', $persister);
     $itemPersister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata("Doctrine\\Tests\\ORM\\NotifyChangedRelatedItem"));
     $this->_unitOfWork->setEntityPersister('Doctrine\\Tests\\ORM\\NotifyChangedRelatedItem', $itemPersister);
     $entity = new NotifyChangedEntity();
     $entity->setData('thedata');
     $this->_unitOfWork->persist($entity);
     $this->_unitOfWork->commit();
     $this->assertEquals(1, count($persister->getInserts()));
     $persister->reset();
     $this->assertTrue($this->_unitOfWork->isInIdentityMap($entity));
     $entity->setData('newdata');
     $entity->setTransient('newtransientvalue');
     $this->assertTrue($this->_unitOfWork->isScheduledForDirtyCheck($entity));
     $this->assertEquals(array('data' => array('thedata', 'newdata')), $this->_unitOfWork->getEntityChangeSet($entity));
     $item = new NotifyChangedRelatedItem();
     $entity->getItems()->add($item);
     $item->setOwner($entity);
     $this->_unitOfWork->persist($item);
     $this->_unitOfWork->commit();
     $this->assertEquals(1, count($itemPersister->getInserts()));
     $persister->reset();
     $itemPersister->reset();
     $entity->getItems()->removeElement($item);
     $item->setOwner(null);
     $this->assertTrue($entity->getItems()->isDirty());
     $this->_unitOfWork->commit();
     $updates = $itemPersister->getUpdates();
     $this->assertEquals(1, count($updates));
     $this->assertTrue($updates[0] === $item);
 }