Commit e5d97712 authored by Katherine Walker's avatar Katherine Walker

Merge pull request #502

parents 037ea3b1 a339233f
......@@ -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;
}
......
......@@ -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']);
}
......
......@@ -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 [
......
......@@ -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];
......
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