Commit 30fe986b authored by Katherine Walker's avatar Katherine Walker

PHPLIB-313 Check that MapReduce's finalize option is an instance of JavascriptInterface

parent e1da3856
......@@ -84,8 +84,8 @@ class MapReduce implements Executable
* This is not supported for server versions < 3.4 and will result in an
* exception at execution time if used.
*
* * finalize (MongoDB\BSON\Javascript): Follows the reduce method and
* modifies the output.
* * finalize (MongoDB\BSON\JavascriptInterface): Follows the reduce method
* and modifies the output.
*
* * jsMode (boolean): Specifies whether to convert intermediate data into
* BSON format between the execution of the map and reduce functions.
......@@ -155,7 +155,7 @@ class MapReduce implements Executable
throw InvalidArgumentException::invalidType('"collation" option', $options['collation'], 'array or object');
}
if (isset($options['finalize']) && ! $options['finalize'] instanceof Javascript) {
if (isset($options['finalize']) && ! $options['finalize'] instanceof JavascriptInterface) {
throw InvalidArgumentException::invalidType('"finalize" option', $options['finalize'], 'MongoDB\Driver\Javascript');
}
......
......@@ -64,6 +64,21 @@ class MapReduceFunctionalTest extends FunctionalTestCase
$operation->execute($this->getPrimaryServer());
}
public function testFinalize()
{
$this->createFixtures(3);
$map = new Javascript('function() { emit(this.x, this.y); }');
$reduce = new Javascript('function(key, values) { return Array.sum(values); }');
$out = ['inline' => 1];
$finalize = new Javascript('function(key, reducedValue) { return reducedValue; }');
$operation = new MapReduce($this->getDatabaseName(), $this->getCollectionName(), $map, $reduce, $out, ['finalize' => $finalize]);
$result = $operation->execute($this->getPrimaryServer());
$this->assertNotNull($result);
}
public function testResult()
{
$this->createFixtures(3);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment