From 551f6d05d96b9d25172902a48df4c83149d45738 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Tue, 28 Jun 2011 21:37:53 +0200 Subject: [PATCH] DDC-1230 - Fix bug where UnitOfWork does not set STATE_REMOVE when calling EntityManager#remove() on an entity --- lib/Doctrine/ORM/UnitOfWork.php | 3 +- .../ORM/Functional/BasicFunctionalTest.php | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 3d46303ea..970ade604 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -984,7 +984,7 @@ class UnitOfWork implements PropertyChangedListener if ($this->isInIdentityMap($entity)) { $this->removeFromIdentityMap($entity); } - unset($this->entityInsertions[$oid]); + unset($this->entityInsertions[$oid], $this->entityStates[$oid]); return; // entity has not been persisted yet, so nothing more to do. } @@ -999,6 +999,7 @@ class UnitOfWork implements PropertyChangedListener } if ( ! isset($this->entityDeletions[$oid])) { $this->entityDeletions[$oid] = $entity; + $this->entityStates[$oid] = self::STATE_REMOVED; } } diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php index cb79795bc..572b6c73d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php @@ -140,6 +140,40 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertFalse($user2->address instanceof \Doctrine\ORM\Proxy\Proxy); } + /** + * @group DDC-1230 + */ + public function testRemove() + { + $user = new CmsUser; + $user->name = 'Guilherme'; + $user->username = 'gblanco'; + $user->status = 'developer'; + + $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($user)); + + $this->_em->persist($user); + + $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($user)); + + $this->_em->remove($user); + + $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($user)); + + $this->_em->persist($user); + $this->_em->flush(); + $id = $user->getId(); + + $this->_em->remove($user); + + $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_REMOVED, $this->_em->getUnitOfWork()->getEntityState($user)); + $this->_em->flush(); + + $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($user)); + + $this->assertNull($this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $id)); + } + public function testOneToManyOrphanRemoval() { $user = new CmsUser;