From e574c2dfee66a8d0c043a768f13e64d3b68b7f05 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola <jmikola@gmail.com> Date: Fri, 10 Apr 2015 17:23:21 -0400 Subject: [PATCH] PHPLIB-45: Test listCollections with filter option --- tests/DatabaseFunctionalTest.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/DatabaseFunctionalTest.php b/tests/DatabaseFunctionalTest.php index 607eff6..b49ccf6 100644 --- a/tests/DatabaseFunctionalTest.php +++ b/tests/DatabaseFunctionalTest.php @@ -71,8 +71,8 @@ class DatabaseFunctionalTest extends FunctionalTestCase public function testListCollections() { - $writeResult = $this->manager->executeInsert($this->getNamespace(), array('x' => 1)); - $this->assertEquals(1, $writeResult->getInsertedCount()); + $commandResult = $this->database->createCollection($this->getCollectionName()); + $this->assertCommandSucceeded($commandResult); $collections = $this->database->listCollections(); $this->assertInstanceOf('MongoDB\Model\CollectionInfoIterator', $collections); @@ -82,6 +82,24 @@ class DatabaseFunctionalTest extends FunctionalTestCase } } + public function testListCollectionsWithFilter() + { + $commandResult = $this->database->createCollection($this->getCollectionName()); + $this->assertCommandSucceeded($commandResult); + + $collectionName = $this->getCollectionName(); + $options = array('filter' => array('name' => $collectionName)); + + $collections = $this->database->listCollections($options); + $this->assertInstanceOf('MongoDB\Model\CollectionInfoIterator', $collections); + $this->assertCount(1, $collections); + + foreach ($collections as $collection) { + $this->assertInstanceOf('MongoDB\Model\CollectionInfo', $collection); + $this->assertEquals($collectionName, $collection->getName()); + } + } + /** * Asserts that a collection with the given name exists in the database. * -- 2.18.1