Skip to content

Commit 63fd471

Browse files
committed
Unit tests for Aggregate operation
1 parent 1bedfc9 commit 63fd471

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

tests/Operation/AggregateTest.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace MongoDB\Tests\Operation;
4+
5+
use MongoDB\Operation\Aggregate;
6+
7+
class AggregateTest extends TestCase
8+
{
9+
/**
10+
* @expectedException MongoDB\Exception\InvalidArgumentException
11+
* @expectedExceptionMessage $pipeline is empty
12+
*/
13+
public function testConstructorPipelineArgumentMustNotBeEmpty()
14+
{
15+
new Aggregate($this->getDatabaseName(), $this->getCollectionName(), array());
16+
}
17+
18+
/**
19+
* @expectedException MongoDB\Exception\InvalidArgumentException
20+
* @expectedExceptionMessage $pipeline is not a list (unexpected index: "1")
21+
*/
22+
public function testConstructorPipelineArgumentMustBeAList()
23+
{
24+
new Aggregate($this->getDatabaseName(), $this->getCollectionName(), array(1 => array('$match' => array('x' => 1))));
25+
}
26+
27+
/**
28+
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
29+
* @dataProvider provideInvalidConstructorOptions
30+
*/
31+
public function testConstructorOptionTypeChecks(array $options)
32+
{
33+
new Aggregate($this->getDatabaseName(), $this->getCollectionName(), array(array('$match' => array('x' => 1))), $options);
34+
}
35+
36+
public function provideInvalidConstructorOptions()
37+
{
38+
$options = array();
39+
40+
foreach ($this->getInvalidBooleanValues() as $value) {
41+
$options[][] = array('allowDiskUse' => $value);
42+
}
43+
44+
foreach ($this->getInvalidIntegerValues() as $value) {
45+
$options[][] = array('batchSize' => $value);
46+
}
47+
48+
foreach ($this->getInvalidIntegerValues() as $value) {
49+
$options[][] = array('maxTimeMS' => $value);
50+
}
51+
52+
foreach ($this->getInvalidBooleanValues() as $value) {
53+
$options[][] = array('useCursor' => $value);
54+
}
55+
56+
return $options;
57+
}
58+
59+
/**
60+
* @expectedException MongoDB\Exception\InvalidArgumentException
61+
* @expectedExceptionMessage "batchSize" option should not be used if "useCursor" is false
62+
*/
63+
public function testConstructorBatchSizeOptionRequiresUseCursor()
64+
{
65+
new Aggregate(
66+
$this->getDatabaseName(),
67+
$this->getCollectionName(),
68+
array(array('$match' => array('x' => 1))),
69+
array('batchSize' => 100, 'useCursor' => false)
70+
);
71+
}
72+
}

0 commit comments

Comments
 (0)