Commit 6dddd509 authored by Jeremy Mikola's avatar Jeremy Mikola

Merge pull request #502

parents 966511c8 0ae3d957
...@@ -205,7 +205,7 @@ class Collection ...@@ -205,7 +205,7 @@ class Collection
$options['readConcern'] = $this->readConcern; $options['readConcern'] = $this->readConcern;
} }
if ( ! isset($options['typeMap']) && ( ! isset($options['useCursor']) || $options['useCursor'])) { if ( ! isset($options['typeMap'])) {
$options['typeMap'] = $this->typeMap; $options['typeMap'] = $this->typeMap;
} }
......
...@@ -200,10 +200,6 @@ class Aggregate implements Executable ...@@ -200,10 +200,6 @@ class Aggregate implements Executable
throw new InvalidArgumentException('"batchSize" option should not be used if "useCursor" is false'); 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()) { if (isset($options['readConcern']) && $options['readConcern']->isDefault()) {
unset($options['readConcern']); unset($options['readConcern']);
} }
......
...@@ -5,6 +5,7 @@ namespace MongoDB\Tests\Operation; ...@@ -5,6 +5,7 @@ namespace MongoDB\Tests\Operation;
use MongoDB\Driver\BulkWrite; use MongoDB\Driver\BulkWrite;
use MongoDB\Operation\Aggregate; use MongoDB\Operation\Aggregate;
use MongoDB\Tests\CommandObserver; use MongoDB\Tests\CommandObserver;
use ArrayIterator;
use stdClass; use stdClass;
class AggregateFunctionalTest extends FunctionalTestCase class AggregateFunctionalTest extends FunctionalTestCase
...@@ -103,12 +104,33 @@ class AggregateFunctionalTest extends FunctionalTestCase ...@@ -103,12 +104,33 @@ class AggregateFunctionalTest extends FunctionalTestCase
$this->createFixtures(3); $this->createFixtures(3);
$pipeline = [['$match' => ['_id' => ['$ne' => 2]]]]; $pipeline = [['$match' => ['_id' => ['$ne' => 2]]]];
$operation = new Aggregate($this->getDatabaseName(), $this->getCollectionName(), $pipeline, ['typeMap' => $typeMap]); $operation = new Aggregate($this->getDatabaseName(), $this->getCollectionName(), $pipeline, ['typeMap' => $typeMap]);
$results = iterator_to_array($operation->execute($this->getPrimaryServer())); $results = iterator_to_array($operation->execute($this->getPrimaryServer()));
$this->assertEquals($expectedDocuments, $results); $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() public function provideTypeMapOptionsAndExpectedDocuments()
{ {
return [ return [
......
...@@ -101,20 +101,6 @@ class AggregateTest extends TestCase ...@@ -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() private function getInvalidHintValues()
{ {
return [123, 3.14, true]; 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