Exemplo n.º 1
0
 public function testUnSerialize()
 {
     $ao = new \ArrayObject(range(0, 2));
     $expected = new Result($ao);
     $expected->setCount(50);
     $string = 'C:21:"Mongator\\Query\\Result":64:{a:2:{s:5:"count";i:50;s:4:"data";a:3:{i:0;i:0;i:1;i:1;i:2;i:2;}}}';
     $this->assertEquals($expected, unserialize($string));
 }
Exemplo n.º 2
0
 /**
  * Create a cursor with the data of the query.
  *
  * @return \MongoCursor A cursor with the data of the query.
  */
 public function createCursor()
 {
     $cursor = $this->repository->getCollection()->find($this->criteria, $this->fields);
     if (null !== $this->sort) {
         $cursor->sort($this->sort);
     }
     if (null !== $this->limit) {
         $cursor->limit($this->limit);
     }
     if (null !== $this->skip) {
         $cursor->skip($this->skip);
     }
     if (null !== $this->batchSize) {
         $cursor->batchSize($this->batchSize);
     }
     if (null !== $this->hint) {
         $cursor->hint($this->hint);
     }
     if (null !== $this->slaveOkay) {
         $cursor->slaveOkay($this->slaveOkay);
     }
     if ($this->snapshot) {
         $cursor->snapshot();
     }
     if (null !== $this->timeout) {
         $cursor->timeout($this->timeout);
     }
     $result = new Result($cursor);
     $result->setCount(function () use($cursor) {
         return $cursor->count();
     });
     return $result;
 }