*/ class PersistentCollectionCriteriaTest extends \Doctrine\Tests\OrmFunctionalTestCase { protected function setUp() { $this->useModelSet('company'); parent::setUp(); } public function tearDown() { if ($this->_em) { $this->_em->getConfiguration()->setEntityNamespaces(array()); } parent::tearDown(); } public function loadFixture() { $companyOrganization = new CompanyOrganization(); $this->_em->persist($companyOrganization); $event1 = new CompanyAuction(); $event1->setData('Foo'); $this->_em->persist($event1); $companyOrganization->addEvent($event1); $event2 = new CompanyAuction(); $event2->setData('Bar'); $this->_em->persist($event2); $companyOrganization->addEvent($event2); $this->_em->flush(); unset($companyOrganization); unset($event1); unset($event2); $this->_em->clear(); } public function testCanCountWithoutLoadingPersistentCollection() { $this->loadFixture(); $repository = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyOrganization'); $organizations = $repository->findAll(); $organization = $organizations[0]; $events = $organization->events->matching(new Criteria()); $this->assertInstanceOf('Doctrine\ORM\LazyCriteriaCollection', $events); $this->assertFalse($events->isInitialized()); $this->assertCount(2, $events); $this->assertFalse($events->isInitialized()); // Make sure it works with constraints $events = $organization->events->matching(new Criteria( Criteria::expr()->eq('id', 2) )); $this->assertInstanceOf('Doctrine\ORM\LazyCriteriaCollection', $events); $this->assertFalse($events->isInitialized()); $this->assertCount(1, $events); $this->assertFalse($events->isInitialized()); } }