Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
30fe986b
Commit
30fe986b
authored
Jan 31, 2018
by
Katherine Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-313 Check that MapReduce's finalize option is an instance of JavascriptInterface
parent
e1da3856
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
3 deletions
+18
-3
MapReduce.php
src/Operation/MapReduce.php
+3
-3
MapReduceFunctionalTest.php
tests/Operation/MapReduceFunctionalTest.php
+15
-0
No files found.
src/Operation/MapReduce.php
View file @
30fe986b
...
@@ -84,8 +84,8 @@ class MapReduce implements Executable
...
@@ -84,8 +84,8 @@ class MapReduce implements Executable
* This is not supported for server versions < 3.4 and will result in an
* This is not supported for server versions < 3.4 and will result in an
* exception at execution time if used.
* exception at execution time if used.
*
*
* * finalize (MongoDB\BSON\Javascript
): Follows the reduce method an
d
* * finalize (MongoDB\BSON\Javascript
Interface): Follows the reduce metho
d
* modifies the output.
*
and
modifies the output.
*
*
* * jsMode (boolean): Specifies whether to convert intermediate data into
* * jsMode (boolean): Specifies whether to convert intermediate data into
* BSON format between the execution of the map and reduce functions.
* BSON format between the execution of the map and reduce functions.
...
@@ -155,7 +155,7 @@ class MapReduce implements Executable
...
@@ -155,7 +155,7 @@ class MapReduce implements Executable
throw
InvalidArgumentException
::
invalidType
(
'"collation" option'
,
$options
[
'collation'
],
'array or object'
);
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
Javascript
Interface
)
{
throw
InvalidArgumentException
::
invalidType
(
'"finalize" option'
,
$options
[
'finalize'
],
'MongoDB\Driver\Javascript'
);
throw
InvalidArgumentException
::
invalidType
(
'"finalize" option'
,
$options
[
'finalize'
],
'MongoDB\Driver\Javascript'
);
}
}
...
...
tests/Operation/MapReduceFunctionalTest.php
View file @
30fe986b
...
@@ -64,6 +64,21 @@ class MapReduceFunctionalTest extends FunctionalTestCase
...
@@ -64,6 +64,21 @@ class MapReduceFunctionalTest extends FunctionalTestCase
$operation
->
execute
(
$this
->
getPrimaryServer
());
$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
()
public
function
testResult
()
{
{
$this
->
createFixtures
(
3
);
$this
->
createFixtures
(
3
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment