Beispiel #1
0
 public function testChangeTrackingNotify()
 {
     $pb = $this->getMockPersistenceBuilder();
     $class = $this->dm->getClassMetadata("Doctrine\\ODM\\MongoDB\\Tests\\NotifyChangedDocument");
     $persister = $this->getMockDocumentPersister($pb, $class);
     $this->uow->setDocumentPersister('Doctrine\\ODM\\MongoDB\\Tests\\NotifyChangedDocument', $persister);
     $pb = $this->getMockPersistenceBuilder();
     $class = $this->dm->getClassMetadata("Doctrine\\ODM\\MongoDB\\Tests\\NotifyChangedRelatedItem");
     $itemPersister = $this->getMockDocumentPersister($pb, $class);
     $this->uow->setDocumentPersister('Doctrine\\ODM\\MongoDB\\Tests\\NotifyChangedRelatedItem', $itemPersister);
     $entity = new NotifyChangedDocument();
     $entity->setData('thedata');
     $this->uow->persist($entity);
     $this->uow->commit();
     $this->assertEquals(1, count($persister->getInserts()));
     $persister->reset();
     $this->assertTrue($this->uow->isInIdentityMap($entity));
     $entity->setData('newdata');
     $entity->setTransient('newtransientvalue');
     $this->assertTrue($this->uow->isScheduledForDirtyCheck($entity));
     $this->assertEquals(array('data' => array('thedata', 'newdata')), $this->uow->getDocumentChangeSet($entity));
     $item = new NotifyChangedRelatedItem();
     $entity->getItems()->add($item);
     $item->setOwner($entity);
     $this->uow->persist($item);
     $this->uow->commit();
     $this->assertEquals(1, count($itemPersister->getInserts()));
     $persister->reset();
     $itemPersister->reset();
     $entity->getItems()->removeElement($item);
     $item->setOwner(null);
     $this->assertTrue($entity->getItems()->isDirty());
     $this->uow->commit();
     $updates = $itemPersister->getUpdates();
     $this->assertEquals(1, count($updates));
     $this->assertTrue($updates[0] === $item);
 }
Beispiel #2
0
 public function testDoubleCommitWithChangeTrackingNotify()
 {
     $pb = $this->getMockPersistenceBuilder();
     $class = $this->dm->getClassMetadata('Doctrine\\ODM\\MongoDB\\Tests\\NotifyChangedDocument');
     $persister = $this->getMockDocumentPersister($pb, $class);
     $this->uow->setDocumentPersister($class->name, $persister);
     $entity = new NotifyChangedDocument();
     $entity->setId(2);
     $this->uow->persist($entity);
     $this->uow->commit($entity);
     // Use a custom error handler that will fail the test if the next commit() call raises a notice error
     set_error_handler(function () {
         restore_error_handler();
         $this->fail('Expected not to get a notice error after committing an entity multiple times using the NOTIFY change tracking policy.');
     }, E_NOTICE);
     $this->uow->commit($entity);
     // Restore previous error handler if no errors have been raised
     restore_error_handler();
 }