Skip to content

Commit 4914b96

Browse files
committed
PHPLIB-281: Allow empty pipeline array for aggregation
1 parent 4dc36f6 commit 4914b96

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

src/Operation/Aggregate.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ class Aggregate implements Executable
111111
*/
112112
public function __construct($databaseName, $collectionName, array $pipeline, array $options = [])
113113
{
114-
if (empty($pipeline)) {
115-
throw new InvalidArgumentException('$pipeline is empty');
116-
}
117-
118114
$expectedIndex = 0;
119115

120116
foreach ($pipeline as $i => $operation) {

tests/Operation/AggregateFunctionalTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ function(stdClass $command) {
5353
);
5454
}
5555

56+
public function testEmptyPipelineReturnsAllDocuments()
57+
{
58+
$this->createFixtures(3);
59+
60+
$operation = new Aggregate($this->getDatabaseName(), $this->getCollectionName(), []);
61+
$results = iterator_to_array($operation->execute($this->getPrimaryServer()));
62+
63+
$expectedDocuments = [
64+
(object) ['_id' => 1, 'x' => (object) ['foo' => 'bar']],
65+
(object) ['_id' => 2, 'x' => (object) ['foo' => 'bar']],
66+
(object) ['_id' => 3, 'x' => (object) ['foo' => 'bar']],
67+
];
68+
69+
$this->assertEquals($expectedDocuments, $results);
70+
}
71+
5672
/**
5773
* @expectedException MongoDB\Driver\Exception\RuntimeException
5874
*/

tests/Operation/AggregateTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@
66

77
class AggregateTest extends TestCase
88
{
9-
/**
10-
* @expectedException MongoDB\Exception\InvalidArgumentException
11-
* @expectedExceptionMessage $pipeline is empty
12-
*/
13-
public function testConstructorPipelineArgumentMustNotBeEmpty()
14-
{
15-
new Aggregate($this->getDatabaseName(), $this->getCollectionName(), []);
16-
}
17-
189
/**
1910
* @expectedException MongoDB\Exception\InvalidArgumentException
2011
* @expectedExceptionMessage $pipeline is not a list (unexpected index: "1")

0 commit comments

Comments
 (0)