From b5ba84f667223145d041f6754564ea9e3a4fb6fc Mon Sep 17 00:00:00 2001 From: Oliver Tischlinger Date: Thu, 4 Dec 2014 15:57:10 +0100 Subject: [PATCH 1/3] matching should not change critera The matching should behave like in ArrayCollection, where it is not changed. The criteria should be cloned so that it could be used for more than one matching operation. --- lib/Doctrine/ORM/PersistentCollection.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index c79130c65..4a56230df 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -878,6 +878,7 @@ final class PersistentCollection implements Collection, Selectable $expression = $criteria->getWhereExpression(); $expression = $expression ? $builder->andX($expression, $ownerExpression) : $ownerExpression; + $criteria = clone $critera; $criteria->where($expression); $persister = $this->em->getUnitOfWork()->getEntityPersister($this->association['targetEntity']); From f8072dd8e0ce718a5bccb530dbb6fd0fe3acc1dc Mon Sep 17 00:00:00 2001 From: Oliver Tischlinger Date: Thu, 4 Dec 2014 16:08:21 +0100 Subject: [PATCH 2/3] Fixed typo --- lib/Doctrine/ORM/PersistentCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index 4a56230df..22404bbc7 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -878,7 +878,7 @@ final class PersistentCollection implements Collection, Selectable $expression = $criteria->getWhereExpression(); $expression = $expression ? $builder->andX($expression, $ownerExpression) : $ownerExpression; - $criteria = clone $critera; + $criteria = clone $criteria; $criteria->where($expression); $persister = $this->em->getUnitOfWork()->getEntityPersister($this->association['targetEntity']); From e9fd5678a566fc4314ceda7967a3c4efbc8d49b5 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 08:30:16 +0100 Subject: [PATCH 3/3] #1206 DDC-3430 - `PersistentCollection` should not mutate the given `Criteria` instances when `matching()` --- .../Functional/PersistentCollectionTest.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php index 375f7d3f9..c2181b8b1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\Common\Collections\Criteria; use Doctrine\Common\Persistence\PersistentObject; /** @@ -69,6 +70,29 @@ class PersistentCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertFalse($collection->isEmpty()); $this->assertFalse($collection->isInitialized()); } + + /** + * @group #1206 + * @group DDC-3430 + */ + public function testMatchingDoesNotModifyTheGivenCriteria() + { + $collectionHolder = new PersistentCollectionHolder(); + + $this->_em->persist($collectionHolder); + $this->_em->flush(); + $this->_em->clear(); + + $criteria = new Criteria(); + + $collectionHolder = $this->_em->find(__NAMESPACE__ . '\PersistentCollectionHolder', $collectionHolder->getId()); + $collectionHolder->getCollection()->matching($criteria); + + $this->assertEmpty($criteria->getWhereExpression()); + $this->assertEmpty($criteria->getFirstResult()); + $this->assertEmpty($criteria->getMaxResults()); + $this->assertEmpty($criteria->getOrderings()); + } } /**