From 52fbe35bc73f93ecf5520a236defacc3df05a612 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 24 Jan 2015 12:20:33 +0100 Subject: [PATCH] #1169 DDC-3343 - correcting query count assertions on extra-lazy specific tests (some DELETE operations became UPDATE operations) Conflicts: lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php --- .../Functional/ExtraLazyCollectionTest.php | 89 ++++++++++++++++++- 1 file changed, 87 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php index eb4dbe4d8..6005dda6c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php @@ -363,7 +363,8 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->articles->removeElement($article); $this->assertFalse($user->articles->isInitialized(), "Post-Condition: Collection is not initialized."); - $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount()); + // NOTE: +2 queries because CmsArticle is a versioned entity, and that needs to be handled accordingly + $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount()); // Test One to Many removal with Entity state as new $article = new \Doctrine\Tests\Models\CMS\CmsArticle(); @@ -384,7 +385,7 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase $user->articles->removeElement($article); - $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Removing a persisted entity should cause one query to be executed."); + $this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Removing a persisted entity will not cause queries when the owning side doesn't actually change."); $this->assertFalse($user->articles->isInitialized(), "Post-Condition: Collection is not initialized."); // Test One to Many removal with Entity state as managed @@ -401,6 +402,90 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Removing a managed entity should cause no query to be executed."); } + /** + * @group DDC-2504 + */ + public function testRemovalOfManagedElementFromOneToManyJoinedInheritanceCollectionDoesNotInitializeIt() + { + $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId); + $childClass = $this->_em->find(DDC2504ChildClass::CLASSNAME, $this->ddc2504ChildClassId); + + $queryCount = $this->getCurrentQueryCount(); + + $otherClass->childClasses->removeElement($childClass); + + $this->assertFalse($otherClass->childClasses->isInitialized(), 'Collection is not initialized.'); + + $this->assertEquals( + $queryCount + 1, + $this->getCurrentQueryCount(), + 'The owning side of the association is updated' + ); + + $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, + $this->getCurrentQueryCount(), + 'No queries are executed, as the owning side of the association is not actually updated.' + ); + $this->assertFalse($otherClass->childClasses->isInitialized(), 'Collection is not initialized.'); + } + /** * */