Skip to content

Commit 53c481c

Browse files
committed
ListCollections functional tests
1 parent aee5a0c commit 53c481c

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace MongoDB\Tests\Operation;
4+
5+
use MongoDB\Driver\Server;
6+
use MongoDB\Operation\DropDatabase;
7+
use MongoDB\Operation\ListCollections;
8+
9+
class ListCollectionsFunctionalTest extends FunctionalTestCase
10+
{
11+
public function testListCollectionsForNewlyCreatedDatabase()
12+
{
13+
$server = $this->getPrimaryServer();
14+
15+
$operation = new DropDatabase($this->getDatabaseName());
16+
$operation->execute($server);
17+
18+
$writeResult = $this->manager->executeInsert($this->getNamespace(), ['x' => 1]);
19+
$this->assertEquals(1, $writeResult->getInsertedCount());
20+
21+
$operation = new ListCollections($this->getDatabaseName(), ['filter' => ['name' => $this->getCollectionName()]]);
22+
// Convert the CollectionInfoIterator to an array since we cannot rewind its cursor
23+
$collections = iterator_to_array($operation->execute($server));
24+
25+
$this->assertCount(1, $collections);
26+
27+
foreach ($collections as $collection) {
28+
$this->assertInstanceOf('MongoDB\Model\CollectionInfo', $collection);
29+
$this->assertEquals($this->getCollectionName(), $collection->getName());
30+
}
31+
}
32+
33+
public function testListCollectionsForNonexistentDatabase()
34+
{
35+
$server = $this->getPrimaryServer();
36+
37+
$operation = new DropDatabase($this->getDatabaseName());
38+
$operation->execute($server);
39+
40+
$operation = new ListCollections($this->getDatabaseName());
41+
$collections = $operation->execute($server);
42+
43+
$this->assertCount(0, $collections);
44+
}
45+
}

0 commit comments

Comments
 (0)