From 03523c67d5bd6bc71bd13fba0e2d26a842f531c5 Mon Sep 17 00:00:00 2001 From: Oliver Tischlinger Date: Thu, 24 Sep 2015 11:39:14 +0200 Subject: [PATCH] add Unit Test for isEmpty change in LazyCriteriaCollection --- .../Tests/ORM/LazyCriteriaCollectionTest.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php b/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php index 2f228f98b..42965f268 100644 --- a/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/LazyCriteriaCollectionTest.php @@ -103,4 +103,28 @@ class LazyCriteriaCollectionTest extends PHPUnit_Framework_TestCase $this->assertEquals(array($foo), $this->lazyCriteriaCollection->matching($criteria)->toArray()); } + + public function testIsEmptyUsesCountWhenNotInitialized() + { + $this->persister->expects($this->once())->method('count')->with($this->criteria)->will($this->returnValue(0)); + + $this->assertTrue($this->lazyCriteriaCollection->isEmpty()); + } + + public function testIsEmptyUsesWrappedCollectionWhenInitialized() + { + $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->assertFalse($this->lazyCriteriaCollection->isEmpty()); + } }