diff --git a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php index 308b3aad2..a94542949 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php @@ -532,6 +532,67 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertFalse($otherClass->childClasses->contains($childClass)); } + /** + * @group DDC-2504 + */ + public function testRemovalOfNonManagedElementFromOneToManyJoinedInheritanceCollectionDoesNotInitializeIt() + { + $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId); + $queryCount = $this->getCurrentQueryCount(); + + $otherClass->childClasses->removeElement(new DDC2504ChildClass()); + + $this->assertEquals( + $queryCount, + $this->getCurrentQueryCount(), + 'Removing an unmanaged entity should cause no query to be executed.' + ); + } + + /** + * @group DDC-2504 + */ + public function testRemovalOfNewElementFromOneToManyJoinedInheritanceCollectionDoesNotInitializeIt() + { + $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId); + $childClass = new DDC2504ChildClass(); + + $this->_em->persist($childClass); + + $queryCount = $this->getCurrentQueryCount(); + + $otherClass->childClasses->removeElement($childClass); + + $this->assertEquals( + $queryCount, + $this->getCurrentQueryCount(), + 'Removing a new entity should cause no query to be executed.' + ); + } + + /** + * @group DDC-2504 + */ + public function testRemovalOfNewManagedElementFromOneToManyJoinedInheritanceCollectionDoesNotInitializeIt() + { + $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId); + $childClass = new DDC2504ChildClass(); + + $this->_em->persist($childClass); + $this->_em->flush(); + + $queryCount = $this->getCurrentQueryCount(); + + $otherClass->childClasses->removeElement($childClass); + + $this->assertEquals( + $queryCount + 2, + $this->getCurrentQueryCount(), + 'Removing a persisted entity should cause two queries to be executed.' + ); + $this->assertFalse($otherClass->childClasses->isInitialized(), 'Collection is not initialized.'); + } + /** * @group DDC-2504 */