Skip to content

Commit 6dddd50

Browse files
committed
Merge pull request #502
2 parents 966511c + 0ae3d95 commit 6dddd50

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

src/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public function aggregate(array $pipeline, array $options = [])
205205
$options['readConcern'] = $this->readConcern;
206206
}
207207

208-
if ( ! isset($options['typeMap']) && ( ! isset($options['useCursor']) || $options['useCursor'])) {
208+
if ( ! isset($options['typeMap'])) {
209209
$options['typeMap'] = $this->typeMap;
210210
}
211211

src/Operation/Aggregate.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,6 @@ public function __construct($databaseName, $collectionName, array $pipeline, arr
200200
throw new InvalidArgumentException('"batchSize" option should not be used if "useCursor" is false');
201201
}
202202

203-
if (isset($options['typeMap']) && ! $options['useCursor']) {
204-
throw new InvalidArgumentException('"typeMap" option should not be used if "useCursor" is false');
205-
}
206-
207203
if (isset($options['readConcern']) && $options['readConcern']->isDefault()) {
208204
unset($options['readConcern']);
209205
}

tests/Operation/AggregateFunctionalTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use MongoDB\Driver\BulkWrite;
66
use MongoDB\Operation\Aggregate;
77
use MongoDB\Tests\CommandObserver;
8+
use ArrayIterator;
89
use stdClass;
910

1011
class AggregateFunctionalTest extends FunctionalTestCase
@@ -103,12 +104,33 @@ public function testTypeMapOption(array $typeMap = null, array $expectedDocument
103104
$this->createFixtures(3);
104105

105106
$pipeline = [['$match' => ['_id' => ['$ne' => 2]]]];
107+
106108
$operation = new Aggregate($this->getDatabaseName(), $this->getCollectionName(), $pipeline, ['typeMap' => $typeMap]);
107109
$results = iterator_to_array($operation->execute($this->getPrimaryServer()));
108110

109111
$this->assertEquals($expectedDocuments, $results);
110112
}
111113

114+
/**
115+
* @dataProvider provideTypeMapOptionsAndExpectedDocuments
116+
*/
117+
public function testTypeMapOptionWithoutCursor(array $typeMap = null, array $expectedDocuments)
118+
{
119+
if (version_compare($this->getServerVersion(), '3.6.0', '>=')) {
120+
$this->markTestSkipped('Aggregations with useCursor == false are not supported');
121+
}
122+
123+
$this->createFixtures(3);
124+
125+
$pipeline = [['$match' => ['_id' => ['$ne' => 2]]]];
126+
127+
$operation = new Aggregate($this->getDatabaseName(), $this->getCollectionName(), $pipeline, ['typeMap' => $typeMap, 'useCursor' => false]);
128+
$results = $operation->execute($this->getPrimaryServer());
129+
130+
$this->assertInstanceOf(ArrayIterator::class, $results);
131+
$this->assertEquals($expectedDocuments, iterator_to_array($results));
132+
}
133+
112134
public function provideTypeMapOptionsAndExpectedDocuments()
113135
{
114136
return [

tests/Operation/AggregateTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,6 @@ public function testConstructorBatchSizeOptionRequiresUseCursor()
101101
);
102102
}
103103

104-
/**
105-
* @expectedException MongoDB\Exception\InvalidArgumentException
106-
* @expectedExceptionMessage "typeMap" option should not be used if "useCursor" is false
107-
*/
108-
public function testConstructorTypeMapOptionRequiresUseCursor()
109-
{
110-
new Aggregate(
111-
$this->getDatabaseName(),
112-
$this->getCollectionName(),
113-
[['$match' => ['x' => 1]]],
114-
['typeMap' => ['root' => 'array'], 'useCursor' => false]
115-
);
116-
}
117-
118104
private function getInvalidHintValues()
119105
{
120106
return [123, 3.14, true];

0 commit comments

Comments
 (0)