From d2174a893a44accca837b0b8fb35a2eadd4e76b5 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 May 2014 18:56:42 +0200 Subject: [PATCH] Verifying that `count` is not called on the persister when the collection is initialized --- .../Tests/ORM/LazyCriteriaCollectionTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php b/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php index 2d5209cf4..5f274a7b0 100644 --- a/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php @@ -56,4 +56,21 @@ class LazyCriteriaCollectionTest extends PHPUnit_Framework_TestCase $this->assertSame(0, $this->lazyCriteriaCollection->count()); $this->assertSame(0, $this->lazyCriteriaCollection->count()); } + + public function testCountUsesWrappedCollectionWhenInitialized() + { + $this + ->persister + ->expects($this->once()) + ->method('loadCriteria') + ->with($this->criteria) + ->will($this->returnValue(array('foo', 'bar', 'baz'))); + + // should never call the persister's count + $this->persister->expects($this->never())->method('count'); + + $this->assertSame(array('foo', 'bar', 'baz'), $this->lazyCriteriaCollection->toArray()); + + $this->assertSame(3, $this->lazyCriteriaCollection->count()); + } }