Doctrine\MongoDB\Tests\Query\BuilderTest::testMapReduceQueryWithSingleMethod PHP Method

testMapReduceQueryWithSingleMethod() public method

    public function testMapReduceQueryWithSingleMethod()
    {
        $map = 'function() {
            for(i = 0; i <= this.options.length; i++) {
                emit(this.name, { count: 1 });
            }
        }';
        $reduce = 'function(product, values) {
            var total = 0
            values.forEach(function(value){
                total+= value.count;
            });
            return {
                product: product,
                options: total,
                test: values
            };
        }';
        $finalize = 'function (key, value) { return value; }';
        $out = ['inline' => true];
        $qb = $this->getTestQueryBuilder()->mapReduce($map, $reduce, $out, ['finalize' => $finalize]);
        $expectedMapReduce = ['map' => $map, 'reduce' => $reduce, 'out' => ['inline' => true], 'options' => ['finalize' => $finalize]];
        $this->assertEquals(Query::TYPE_MAP_REDUCE, $qb->getType());
        $this->assertEquals($expectedMapReduce, $qb->debug('mapReduce'));
    }
BuilderTest