Skip to content

Commit

Permalink
Merge branch 'fix/#5689-avoid-object-hash-conflicts-due-to-merge-oper…
Browse files Browse the repository at this point in the history
…ations'

Close #5689
  • Loading branch information
Ocramius committed Sep 10, 2016
2 parents 3e3bfbf + 503b211 commit 2210505
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 0 additions & 2 deletions lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -3404,8 +3404,6 @@ private function mergeEntityStateIntoManagedCopy($entity, $managedCopy)
);
$managedCol->setOwner($managedCopy, $assoc2);
$prop->setValue($managedCopy, $managedCol);

$this->originalEntityData[spl_object_hash($entity)][$name] = $managedCol;
}

if ($assoc2['isCascadeMerge']) {
Expand Down
29 changes: 29 additions & 0 deletions tests/Doctrine/Tests/ORM/UnitOfWorkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Doctrine\Tests\Mocks\EntityPersisterMock;
use Doctrine\Tests\Mocks\UnitOfWorkMock;
use Doctrine\Tests\Models\CMS\CmsPhonenumber;
use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\Models\Forum\ForumAvatar;
use Doctrine\Tests\Models\Forum\ForumUser;
use Doctrine\Tests\Models\GeoNames\City;
Expand Down Expand Up @@ -459,6 +460,34 @@ public function entitiesWithInvalidIdentifiersProvider()
'second null string, two fields' => [$secondNullString, ['id1' => $secondNullString->id1, 'id2' => null]],
];
}

/**
* @group 5689
* @group 1465
*/
public function testObjectHashesOfMergedEntitiesAreNotUsedInOriginalEntityDataMap()
{
$user = new CmsUser();
$user->name = 'ocramius';
$mergedUser = $this->_unitOfWork->merge($user);

self::assertSame([], $this->_unitOfWork->getOriginalEntityData($user), 'No original data was stored');
self::assertSame([], $this->_unitOfWork->getOriginalEntityData($mergedUser), 'No original data was stored');


$user = null;
$mergedUser = null;

// force garbage collection of $user (frees the used object hashes, which may be recycled)
gc_collect_cycles();

$newUser = new CmsUser();
$newUser->name = 'ocramius';

$this->_unitOfWork->persist($newUser);

self::assertSame([], $this->_unitOfWork->getOriginalEntityData($newUser), 'No original data was stored');
}
}

/**
Expand Down

0 comments on commit 2210505

Please sign in to comment.