From 7c1ebd99bc051ef9717fe431eef8cf6ad836b3b5 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 13 Jul 2017 08:16:00 +0200 Subject: [PATCH 1/2] Fix return of removeElement on collections Fixes #5745 --- lib/Doctrine/ORM/PersistentCollection.php | 6 +----- .../Tests/ORM/Functional/ExtraLazyCollectionTest.php | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index c2e11dfbe..a4b579b7e 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -375,11 +375,7 @@ final class PersistentCollection extends AbstractLazyCollection implements Selec $persister = $this->em->getUnitOfWork()->getCollectionPersister($this->association); - if ($persister->removeElement($this, $element)) { - return $element; - } - - return null; + return $persister->removeElement($this, $element); } $removed = parent::removeElement($element); diff --git a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php index 731a0826d..9ed16217f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php @@ -636,7 +636,7 @@ class ExtraLazyCollectionTest extends OrmFunctionalTestCase $group = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId); $queryCount = $this->getCurrentQueryCount(); - $user->groups->removeElement($group); + $this->assertTrue($user->groups->removeElement($group)); $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Removing a persisted entity should cause one query to be executed."); $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized."); From 095b36514668c4e5ab2d26cc430ce248e1ecddd6 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 13 Jul 2017 16:39:06 +0200 Subject: [PATCH 2/2] Add test for removing element not in collection --- tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php index 9ed16217f..8c40ff938 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ExtraLazyCollectionTest.php @@ -641,6 +641,8 @@ class ExtraLazyCollectionTest extends OrmFunctionalTestCase $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Removing a persisted entity should cause one query to be executed."); $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized."); + $this->assertFalse($user->groups->removeElement($group), "Removing an already removed element returns false"); + // Test Many to Many removal with Entity state as new $group = new \Doctrine\Tests\Models\CMS\CmsGroup(); $group->name = "A New group!";