コード例 #1
1
 public function testNext()
 {
     $expectedResults = array(array(1), array(5), array(7));
     $query = new MockQuery();
     $query->setNextResult($expectedResults);
     $createQuery = function ($dql) use($query) {
         $query->setDQL($dql);
         return $query;
     };
     $this->em->expects($this->any())->method('createQuery')->will($this->returnCallback($createQuery));
     $qb = new \Doctrine\ORM\QueryBuilder($this->em);
     $qb->select('a.id, a.name')->from('A', 'a')->where('a.name = :name')->setParameter('name', 'abc');
     // initialize Iterator
     $this->object->setQueryBuilder($qb);
     $this->object->setIterateBy('a.id');
     $this->object->setPageSize(3);
     $this->object->setPullClosure(function ($arr) {
         return $arr[0];
     });
     // initial results
     $this->assertEquals($expectedResults, $this->object->next());
     $this->assertEquals('SELECT a.id, a.name FROM A a WHERE a.name = :name ORDER BY a.id ASC', $query->getDQL());
     $this->assertEquals(3, $query->getLastMaxResults());
     $this->assertEquals(1, \count($query->getLastParameters()));
     // second results
     $query->setNextResult(array());
     $this->assertEquals(array(), $this->object->next());
     $this->assertEquals('SELECT a.id, a.name FROM A a WHERE a.name = :name AND a.id > 7 ORDER BY a.id ASC', $query->getDQL());
     $this->assertEquals(3, $query->getLastMaxResults());
     $this->assertEquals(1, \count($query->getLastParameters()));
 }
コード例 #2
0
 /**
  * Constructor.
  * 
  * @param \Doctrine\ORM\QueryBuilder $qb Traverse query in QueryBuilder form
  * @param int $pageSize Maximum number of results retrieved in each next() call
  */
 public function __construct(QueryBuilder $qb, $pageSize = 10)
 {
     $this->iterator = new Iterator();
     $pullClosure = function ($entity) {
         return $entity->getId();
     };
     $this->iterator->setPullClosure($pullClosure);
     $this->iterator->setPageSize($pageSize);
     $this->setQueryBuilder($qb);
 }