Skip to content

Commit 775ceee

Browse files
committed
PHPLIB-45: Test listCollections with filter option
1 parent 7b20974 commit 775ceee

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

tests/DatabaseFunctionalTest.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public function testDropCollection()
7171

7272
public function testListCollections()
7373
{
74-
$writeResult = $this->manager->executeInsert($this->getNamespace(), array('x' => 1));
75-
$this->assertEquals(1, $writeResult->getInsertedCount());
74+
$commandResult = $this->database->createCollection($this->getCollectionName());
75+
$this->assertCommandSucceeded($commandResult);
7676

7777
$collections = $this->database->listCollections();
7878
$this->assertInstanceOf('MongoDB\Model\CollectionInfoIterator', $collections);
@@ -82,6 +82,24 @@ public function testListCollections()
8282
}
8383
}
8484

85+
public function testListCollectionsWithFilter()
86+
{
87+
$commandResult = $this->database->createCollection($this->getCollectionName());
88+
$this->assertCommandSucceeded($commandResult);
89+
90+
$collectionName = $this->getCollectionName();
91+
$options = array('filter' => array('name' => $collectionName));
92+
93+
$collections = $this->database->listCollections($options);
94+
$this->assertInstanceOf('MongoDB\Model\CollectionInfoIterator', $collections);
95+
$this->assertCount(1, $collections);
96+
97+
foreach ($collections as $collection) {
98+
$this->assertInstanceOf('MongoDB\Model\CollectionInfo', $collection);
99+
$this->assertEquals($collectionName, $collection->getName());
100+
}
101+
}
102+
85103
/**
86104
* Asserts that a collection with the given name exists in the database.
87105
*

0 commit comments

Comments
 (0)