From c68ed4c20498aa6386df5492672df353d48b1547 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 May 2014 19:06:16 +0200 Subject: [PATCH] Verifying that the persister is used only once when matching on a lazy criteria collection --- .../Tests/ORM/LazyCriteriaCollectionTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php b/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php index 5f274a7b0..ef9d72b26 100644 --- a/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php @@ -5,6 +5,7 @@ namespace Doctrine\Tests\ORM; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\LazyCriteriaCollection; use Doctrine\Tests\Mocks\ConnectionMock; +use stdClass; use PHPUnit_Framework_TestCase; /** @@ -73,4 +74,33 @@ class LazyCriteriaCollectionTest extends PHPUnit_Framework_TestCase $this->assertSame(3, $this->lazyCriteriaCollection->count()); } + + public function testMatchingUsesThePersisterOnlyOnce() + { + $foo = new stdClass(); + $bar = new stdClass(); + $baz = new stdClass(); + + $foo->val = 'foo'; + $bar->val = 'bar'; + $baz->val = 'baz'; + + $this + ->persister + ->expects($this->once()) + ->method('loadCriteria') + ->with($this->criteria) + ->will($this->returnValue(array($foo, $bar, $baz))); + + $criteria = new Criteria(); + + $criteria->andWhere($criteria->expr()->eq('val', 'foo')); + + $filtered = $this->lazyCriteriaCollection->matching($criteria); + + $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $filtered); + $this->assertEquals(array($foo), $filtered->toArray()); + + $this->assertEquals(array($foo), $this->lazyCriteriaCollection->matching($criteria)->toArray()); + } }