Skip to content

Commit 30fe986

Browse files
committed
PHPLIB-313 Check that MapReduce's finalize option is an instance of JavascriptInterface
1 parent e1da385 commit 30fe986

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/Operation/MapReduce.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ class MapReduce implements Executable
8484
* This is not supported for server versions < 3.4 and will result in an
8585
* exception at execution time if used.
8686
*
87-
* * finalize (MongoDB\BSON\Javascript): Follows the reduce method and
88-
* modifies the output.
87+
* * finalize (MongoDB\BSON\JavascriptInterface): Follows the reduce method
88+
* and modifies the output.
8989
*
9090
* * jsMode (boolean): Specifies whether to convert intermediate data into
9191
* BSON format between the execution of the map and reduce functions.
@@ -155,7 +155,7 @@ public function __construct($databaseName, $collectionName, JavascriptInterface
155155
throw InvalidArgumentException::invalidType('"collation" option', $options['collation'], 'array or object');
156156
}
157157

158-
if (isset($options['finalize']) && ! $options['finalize'] instanceof Javascript) {
158+
if (isset($options['finalize']) && ! $options['finalize'] instanceof JavascriptInterface) {
159159
throw InvalidArgumentException::invalidType('"finalize" option', $options['finalize'], 'MongoDB\Driver\Javascript');
160160
}
161161

tests/Operation/MapReduceFunctionalTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ function(stdClass $command) {
6464
$operation->execute($this->getPrimaryServer());
6565
}
6666

67+
public function testFinalize()
68+
{
69+
$this->createFixtures(3);
70+
71+
$map = new Javascript('function() { emit(this.x, this.y); }');
72+
$reduce = new Javascript('function(key, values) { return Array.sum(values); }');
73+
$out = ['inline' => 1];
74+
$finalize = new Javascript('function(key, reducedValue) { return reducedValue; }');
75+
76+
$operation = new MapReduce($this->getDatabaseName(), $this->getCollectionName(), $map, $reduce, $out, ['finalize' => $finalize]);
77+
$result = $operation->execute($this->getPrimaryServer());
78+
79+
$this->assertNotNull($result);
80+
}
81+
6782
public function testResult()
6883
{
6984
$this->createFixtures(3);

0 commit comments

Comments
 (0)