Doctrine\MongoDB\Tests\Query\QueryTest::testGroup PHP Method

testGroup() public method

public testGroup ( )
    public function testGroup()
    {
        $keys = ['a' => 1];
        $initial = ['count' => 0, 'sum' => 0];
        $reduce = 'function(obj, prev) { prev.count++; prev.sum += obj.a; }';
        $finalize = 'function(obj) { if (obj.count) { obj.avg = obj.sum / obj.count; } else { obj.avg = 0; } }';
        $queryArray = ['type' => Query::TYPE_GROUP, 'group' => ['keys' => $keys, 'initial' => $initial, 'reduce' => $reduce, 'options' => ['finalize' => $finalize]], 'query' => ['type' => 1]];
        $collection = $this->getMockCollection();
        $collection->expects($this->once())->method('group')->with($keys, $initial, $reduce, ['finalize' => $finalize, 'cond' => ['type' => 1]]);
        $query = new Query($collection, $queryArray, []);
        $query->execute();
    }