Пример #1
0
 /**
  * @see \Doctrine\MongoDB\EagerCursor::current()
  * @see http://php.net/manual/en/iterator.current.php
  */
 public function current()
 {
     $current = parent::current();
     if ($current === null || !$this->hydrate) {
         return $current;
     }
     return $this->unitOfWork->getOrCreateDocument($this->class->name, $current, $this->unitOfWorkHints);
 }
Пример #2
0
 public function testIterationMethods()
 {
     $results = array(array('_id' => 1, 'x' => 'foo'), array('_id' => 2, 'x' => 'bar'));
     $cursor = $this->getMockCursor();
     $cursor->expects($this->once())->method('toArray')->will($this->returnValue($results));
     $eagerCursor = new EagerCursor($cursor);
     $this->assertFalse($eagerCursor->isInitialized());
     foreach (range(1, 2) as $_) {
         $this->assertEquals(0, $eagerCursor->key());
         $this->assertTrue($eagerCursor->isInitialized());
         $this->assertEquals($results[0], $eagerCursor->current());
         $eagerCursor->next();
         $this->assertEquals(1, $eagerCursor->key());
         $this->assertEquals($results[1], $eagerCursor->current());
         $eagerCursor->next();
         $this->assertFalse($eagerCursor->valid());
         $eagerCursor->rewind();
     }
 }
Пример #3
0
 public function testGetNextHasNext()
 {
     $results = array(array('_id' => 1, 'x' => 'foo'), array('_id' => 2, 'x' => 'bar'));
     $cursor = $this->getMockCursor();
     $cursor->expects($this->once())->method('toArray')->will($this->returnValue($results));
     $eagerCursor = new EagerCursor($cursor);
     $this->assertTrue($eagerCursor->hasNext());
     $this->assertEquals($results[0], $eagerCursor->getNext());
     $this->assertTrue($eagerCursor->hasNext());
     $this->assertEquals($results[0], $eagerCursor->current(), 'hasNext does not advance internal cursor');
     $this->assertEquals($results[1], $eagerCursor->getNext());
     $this->assertFalse($eagerCursor->hasNext());
     $this->assertNull($eagerCursor->getNext());
     $eagerCursor->rewind();
     $this->assertTrue($eagerCursor->hasNext());
     $this->assertEquals($results[0], $eagerCursor->getNext());
 }