Пример #1
0
 /**
  * @expectedException \RuntimeException
  */
 public function testMapReduceRuntimeExceptionOnError()
 {
     $collectionName = 'myCollectionName';
     $result = array('ok' => false, 'errmsg' => $errmsg = 'foobarbarfooups');
     $mongoDB = $this->getMockBuilder('MongoDB')->disableOriginalConstructor()->getMock();
     $mongoDB->expects($this->once())->method('command')->will($this->returnValue($result));
     $connection = $this->getMock('Mandango\\ConnectionInterface');
     $connection->expects($this->any())->method('getMongoDB')->will($this->returnValue($mongoDB));
     $repository = new RepositoryMock($this->mandango);
     $repository->setCollectionName($collectionName);
     $repository->setConnection($connection);
     $repository->mapReduce('foo', 'bar', array('inline' => 1));
 }
Пример #2
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);
 }
Пример #3
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));
 }