Skip to content

Commit cb62bea

Browse files
committed
WIP: PHPLIB-58: CRUD spec functional tests
1 parent f3492fb commit cb62bea

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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->assertEquals(3, $this->collection->insertMany(array(
29+
array('_id' => 1, 'x' => 11),
30+
array('_id' => 2, 'x' => 22),
31+
array('_id' => 3, 'x' => 33),
32+
))->getInsertedCount());
33+
34+
$cursor = $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, $cursor->toArray());
48+
}
49+
50+
public function testAggregateWithOut()
51+
{
52+
$outputCollection = new Collection($this->manager, $this->getNamespace() . '_output');
53+
$this->assertCommandSucceeded($outputCollection->drop());
54+
55+
$this->assertEquals(3, $this->collection->insertMany(array(
56+
array('_id' => 1, 'x' => 11),
57+
array('_id' => 2, 'x' => 22),
58+
array('_id' => 3, 'x' => 33),
59+
))->getInsertedCount());
60+
61+
$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+
);
68+
69+
$expected = array(
70+
array('_id' => 2, 'x' => 22),
71+
array('_id' => 3, 'x' => 33),
72+
);
73+
74+
$this->assertEquals($expected, $outputCollection->find()->toArray());
75+
}
76+
}
77+

0 commit comments

Comments
 (0)