Пример #1
0
 public function testAggregate()
 {
     $pipeline = [['$match' => ['status' => 'A']], ['$group' => ['_id' => '$cust_id', 'total' => ['$sum' => 'amount']]]];
     $result = [['_id' => 'a1', 'total' => 321], ['_id' => 'a2', 'total' => 87]];
     $collection = $this->getMockBuilder('\\MongoDB\\Collection')->disableOriginalConstructor()->getMock();
     $collection->expects($this->once())->method('aggregate')->with($pipeline)->will($this->returnValue($result));
     $repository = new RepositoryMock($this->mandango);
     $repository->setCollection($collection);
     $repository->aggregate($pipeline);
 }
Пример #2
0
 public function testGroup()
 {
     $keys = array('category' => 1);
     $initial = array('items' => array());
     $reduce = 'function (obj, prev) { prev.items.push(obj.name); }';
     $options = array();
     $result = array(new \DateTime());
     $collection = $this->getMockBuilder('MongoCollection')->disableOriginalConstructor()->getMock();
     $collection->expects($this->once())->method('group')->with($keys, $initial, $reduce, $options)->will($this->returnValue($result));
     $repository = new RepositoryMock($this->mandango);
     $repository->setCollection($collection);
     $this->assertSame($result, $repository->group($keys, $initial, $reduce, $options));
 }