1
0
mirror of synced 2025-03-23 08:23:51 +03:00

Verifying that the persister is used only once when matching on a lazy criteria collection

This commit is contained in:
Marco Pivetta 2014-05-17 19:06:16 +02:00
parent d2174a893a
commit c68ed4c204

View File

@ -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());
}
}