Commit 4914b968 authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-281: Allow empty pipeline array for aggregation

parent 4dc36f62
......@@ -111,10 +111,6 @@ class Aggregate implements Executable
*/
public function __construct($databaseName, $collectionName, array $pipeline, array $options = [])
{
if (empty($pipeline)) {
throw new InvalidArgumentException('$pipeline is empty');
}
$expectedIndex = 0;
foreach ($pipeline as $i => $operation) {
......
......@@ -53,6 +53,22 @@ class AggregateFunctionalTest extends FunctionalTestCase
);
}
public function testEmptyPipelineReturnsAllDocuments()
{
$this->createFixtures(3);
$operation = new Aggregate($this->getDatabaseName(), $this->getCollectionName(), []);
$results = iterator_to_array($operation->execute($this->getPrimaryServer()));
$expectedDocuments = [
(object) ['_id' => 1, 'x' => (object) ['foo' => 'bar']],
(object) ['_id' => 2, 'x' => (object) ['foo' => 'bar']],
(object) ['_id' => 3, 'x' => (object) ['foo' => 'bar']],
];
$this->assertEquals($expectedDocuments, $results);
}
/**
* @expectedException MongoDB\Driver\Exception\RuntimeException
*/
......
......@@ -6,15 +6,6 @@ use MongoDB\Operation\Aggregate;
class AggregateTest extends TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage $pipeline is empty
*/
public function testConstructorPipelineArgumentMustNotBeEmpty()
{
new Aggregate($this->getDatabaseName(), $this->getCollectionName(), []);
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage $pipeline is not a list (unexpected index: "1")
......
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