Skip to content

Commit 0112b46

Browse files
committed
WIP: PHPLIB-58: CRUD spec functional tests
1 parent 1354a59 commit 0112b46

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
namespace MongoDB\Tests\Collection;
4+
5+
use MongoDB\Collection;
6+
use MongoDB\Driver\Manager;
7+
use MongoDB\Tests\FunctionalTestCase;
8+
9+
/**
10+
* Functional tests from the CRUD specification.
11+
*
12+
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
13+
*/
14+
class CrudSpecFunctionalTest extends FunctionalTestCase
15+
{
16+
private $collection;
17+
18+
public function setUp()
19+
{
20+
parent::setUp();
21+
22+
$this->collection = new Collection($this->manager, $this->getNamespace());
23+
$this->collection->deleteMany(array());
24+
}
25+
26+
public function testAggregateWithMultipleStages()
27+
{
28+
$this->collection->insertMany(array(
29+
array('_id' => 1, 'x' => 11),
30+
array('_id' => 2, 'x' => 22),
31+
array('_id' => 3, 'x' => 33),
32+
));
33+
34+
$result = $this->collection->aggregate(
35+
array(
36+
array('$sort' => array('x' => 1)),
37+
array('$match' => array('_id' => array('$gt' => 1))),
38+
),
39+
array('batchSize' => 2)
40+
);
41+
42+
$expected = array(
43+
array('_id' => 2, 'x' => 22),
44+
array('_id' => 3, 'x' => 33),
45+
);
46+
47+
$this->assertEquals($expected, iterator_to_array($result));
48+
}
49+
50+
public function testAggregateWithOut()
51+
{
52+
$this->collection->insertMany(array(
53+
array('_id' => 1, 'x' => 11),
54+
array('_id' => 2, 'x' => 22),
55+
array('_id' => 3, 'x' => 33),
56+
));
57+
58+
$outputCollection = new Collection($this->manager, $this->getNamespace() . '_output');
59+
$outputCollection->deleteMany(array());
60+
61+
$result = $this->collection->aggregate(
62+
array(
63+
array('$sort' => array('x' => 1)),
64+
array('$match' => array('_id' => array('$gt' => 1))),
65+
array('$out' => $outputCollection->getCollectionName()),
66+
),
67+
array('batchSize' => 2)
68+
);
69+
70+
$expected = array(
71+
array('_id' => 2, 'x' => 22),
72+
array('_id' => 3, 'x' => 33),
73+
);
74+
75+
$this->assertEquals($expected, iterator_to_array($outputCollection->find()));
76+
}
77+
}
78+

0 commit comments

Comments
 (0)