Skip to content

Commit

Permalink
Merge pull request #1257 from banrobert/master
Browse files Browse the repository at this point in the history
NOTIFY change tracking policy fixes
  • Loading branch information
malarzm committed Oct 30, 2015
2 parents de269fb + aeec731 commit 5803418
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ private function computeOrRecomputeChangeSet(ClassMetadata $class, $document, $r
// and we have a copy of the original data
$originalData = $this->originalDocumentData[$oid];
$isChangeTrackingNotify = $class->isChangeTrackingNotify();
if ($isChangeTrackingNotify && ! $recompute) {
if ($isChangeTrackingNotify && ! $recompute && isset($this->documentChangeSets[$oid])) {
$changeSet = $this->documentChangeSets[$oid];
} else {
$changeSet = array();
Expand Down
32 changes: 31 additions & 1 deletion tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,33 @@ public function testChangeTrackingNotify()
$this->assertTrue($updates[0] === $item);
}

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();
}

public function testGetDocumentStateWithAssignedIdentity()
{
$pb = $this->getMockPersistenceBuilder();
Expand Down Expand Up @@ -686,7 +713,10 @@ public function __construct($name)
}
}

/** @ODM\Document */
/**
* @ODM\Document
* @ODM\ChangeTrackingPolicy("NOTIFY")
*/
class NotifyChangedDocument implements \Doctrine\Common\NotifyPropertyChanged
{
private $_listeners = array();
Expand Down

0 comments on commit 5803418

Please sign in to comment.