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
6dddd509
Commit
6dddd509
authored
Feb 27, 2018
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #502
parents
966511c8
0ae3d957
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
19 deletions
+23
-19
Collection.php
src/Collection.php
+1
-1
Aggregate.php
src/Operation/Aggregate.php
+0
-4
AggregateFunctionalTest.php
tests/Operation/AggregateFunctionalTest.php
+22
-0
AggregateTest.php
tests/Operation/AggregateTest.php
+0
-14
No files found.
src/Collection.php
View file @
6dddd509
...
...
@@ -205,7 +205,7 @@ class Collection
$options
[
'readConcern'
]
=
$this
->
readConcern
;
}
if
(
!
isset
(
$options
[
'typeMap'
])
&&
(
!
isset
(
$options
[
'useCursor'
])
||
$options
[
'useCursor'
])
)
{
if
(
!
isset
(
$options
[
'typeMap'
]))
{
$options
[
'typeMap'
]
=
$this
->
typeMap
;
}
...
...
src/Operation/Aggregate.php
View file @
6dddd509
...
...
@@ -200,10 +200,6 @@ class Aggregate implements Executable
throw
new
InvalidArgumentException
(
'"batchSize" option should not be used if "useCursor" is false'
);
}
if
(
isset
(
$options
[
'typeMap'
])
&&
!
$options
[
'useCursor'
])
{
throw
new
InvalidArgumentException
(
'"typeMap" option should not be used if "useCursor" is false'
);
}
if
(
isset
(
$options
[
'readConcern'
])
&&
$options
[
'readConcern'
]
->
isDefault
())
{
unset
(
$options
[
'readConcern'
]);
}
...
...
tests/Operation/AggregateFunctionalTest.php
View file @
6dddd509
...
...
@@ -5,6 +5,7 @@ namespace MongoDB\Tests\Operation;
use
MongoDB\Driver\BulkWrite
;
use
MongoDB\Operation\Aggregate
;
use
MongoDB\Tests\CommandObserver
;
use
ArrayIterator
;
use
stdClass
;
class
AggregateFunctionalTest
extends
FunctionalTestCase
...
...
@@ -103,12 +104,33 @@ class AggregateFunctionalTest extends FunctionalTestCase
$this
->
createFixtures
(
3
);
$pipeline
=
[[
'$match'
=>
[
'_id'
=>
[
'$ne'
=>
2
]]]];
$operation
=
new
Aggregate
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$pipeline
,
[
'typeMap'
=>
$typeMap
]);
$results
=
iterator_to_array
(
$operation
->
execute
(
$this
->
getPrimaryServer
()));
$this
->
assertEquals
(
$expectedDocuments
,
$results
);
}
/**
* @dataProvider provideTypeMapOptionsAndExpectedDocuments
*/
public
function
testTypeMapOptionWithoutCursor
(
array
$typeMap
=
null
,
array
$expectedDocuments
)
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.6.0'
,
'>='
))
{
$this
->
markTestSkipped
(
'Aggregations with useCursor == false are not supported'
);
}
$this
->
createFixtures
(
3
);
$pipeline
=
[[
'$match'
=>
[
'_id'
=>
[
'$ne'
=>
2
]]]];
$operation
=
new
Aggregate
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$pipeline
,
[
'typeMap'
=>
$typeMap
,
'useCursor'
=>
false
]);
$results
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertInstanceOf
(
ArrayIterator
::
class
,
$results
);
$this
->
assertEquals
(
$expectedDocuments
,
iterator_to_array
(
$results
));
}
public
function
provideTypeMapOptionsAndExpectedDocuments
()
{
return
[
...
...
tests/Operation/AggregateTest.php
View file @
6dddd509
...
...
@@ -101,20 +101,6 @@ class AggregateTest extends TestCase
);
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage "typeMap" option should not be used if "useCursor" is false
*/
public
function
testConstructorTypeMapOptionRequiresUseCursor
()
{
new
Aggregate
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[[
'$match'
=>
[
'x'
=>
1
]]],
[
'typeMap'
=>
[
'root'
=>
'array'
],
'useCursor'
=>
false
]
);
}
private
function
getInvalidHintValues
()
{
return
[
123
,
3.14
,
true
];
...
...
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