Exemplo n.º 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);
 }
Exemplo n.º 2
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());
 }
Exemplo n.º 3
0
 /**
  * Prepare the Cursor returned by {@link Query::execute()}.
  *
  * This method will apply cursor options present in the query structure
  * array. The Cursor may also be wrapped with an EagerCursor.
  *
  * @param Cursor $cursor
  * @return CursorInterface
  */
 protected function prepareCursor(Cursor $cursor)
 {
     /* Note: if this cursor resulted from a mapReduce command, applying the
      * read preference may be undesirable. Results would have been written
      * to the primary and replication may still be in progress.
      */
     if (isset($this->query['readPreference'])) {
         $cursor->setReadPreference($this->query['readPreference'], $this->query['readPreferenceTags']);
     }
     foreach ($this->getQueryOptions('hint', 'immortal', 'limit', 'skip', 'slaveOkay', 'sort', 'maxTimeMS') as $key => $value) {
         $cursor->{$key}($value);
     }
     if (!empty($this->query['snapshot'])) {
         $cursor->snapshot();
     }
     if (!empty($this->query['eagerCursor'])) {
         $cursor = new EagerCursor($cursor);
     }
     if (isset($this->query['useIdentifierKeys'])) {
         $cursor->setUseIdentifierKeys($this->query['useIdentifierKeys']);
     }
     return $cursor;
 }
Exemplo n.º 4
0
 public function testSkip()
 {
     $cursor = $this->getMockCursor();
     $offset = 10;
     $cursor->expects($this->once())->method('skip')->with($offset);
     $eagerCursor = new EagerCursor($cursor);
     $result = $eagerCursor->skip($offset);
     $this->assertInstanceOf('\\Doctrine\\MongoDB\\EagerCursor', $result);
 }
Exemplo n.º 5
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();
     }
 }