diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 7ab4046e6..146789397 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1395,6 +1395,7 @@ class UnitOfWork implements PropertyChangedListener if (isset($this->identityMap[$className][$idHash])) { unset($this->identityMap[$className][$idHash]); + unset($this->readOnlyObjects[$oid]); //$this->entityStates[$oid] = self::STATE_DETACHED; @@ -2209,6 +2210,7 @@ class UnitOfWork implements PropertyChangedListener $this->collectionDeletions = $this->collectionUpdates = $this->extraUpdates = + $this->readOnlyObjects = $this->orphanRemovals = array(); if ($this->commitOrderCalculator !== null) { diff --git a/tests/Doctrine/Tests/ORM/Functional/ReadOnlyTest.php b/tests/Doctrine/Tests/ORM/Functional/ReadOnlyTest.php index 44832fc76..2519a9c57 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ReadOnlyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ReadOnlyTest.php @@ -15,9 +15,12 @@ class ReadOnlyTest extends \Doctrine\Tests\OrmFunctionalTestCase { parent::setUp(); - $this->_schemaTool->createSchema(array( - $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ReadOnlyEntity'), - )); + try { + $this->_schemaTool->createSchema(array( + $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\ReadOnlyEntity'), + )); + } catch(\Exception $e) { + } } public function testReadOnlyEntityNeverChangeTracked() @@ -36,6 +39,36 @@ class ReadOnlyTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals("Test1", $dbReadOnly->name); $this->assertEquals(1234, $dbReadOnly->numericValue); } + + /** + * @group DDC-1659 + */ + public function testClearReadOnly() + { + $readOnly = new ReadOnlyEntity("Test1", 1234); + $this->_em->persist($readOnly); + $this->_em->flush(); + $this->_em->getUnitOfWork()->markReadOnly($readOnly); + + $this->_em->clear(); + + $this->assertFalse($this->_em->getUnitOfWork()->isReadOnly($readOnly)); + } + + /** + * @group DDC-1659 + */ + public function testClearEntitiesReadOnly() + { + $readOnly = new ReadOnlyEntity("Test1", 1234); + $this->_em->persist($readOnly); + $this->_em->flush(); + $this->_em->getUnitOfWork()->markReadOnly($readOnly); + + $this->_em->clear(get_class($readOnly)); + + $this->assertFalse($this->_em->getUnitOfWork()->isReadOnly($readOnly)); + } } /** @@ -58,4 +91,4 @@ class ReadOnlyEntity $this->name = $name; $this->numericValue = $number; } -} \ No newline at end of file +}