Commit 53c481c8 authored by Jeremy Mikola's avatar Jeremy Mikola

ListCollections functional tests

parent aee5a0c6
<?php
namespace MongoDB\Tests\Operation;
use MongoDB\Driver\Server;
use MongoDB\Operation\DropDatabase;
use MongoDB\Operation\ListCollections;
class ListCollectionsFunctionalTest extends FunctionalTestCase
{
public function testListCollectionsForNewlyCreatedDatabase()
{
$server = $this->getPrimaryServer();
$operation = new DropDatabase($this->getDatabaseName());
$operation->execute($server);
$writeResult = $this->manager->executeInsert($this->getNamespace(), ['x' => 1]);
$this->assertEquals(1, $writeResult->getInsertedCount());
$operation = new ListCollections($this->getDatabaseName(), ['filter' => ['name' => $this->getCollectionName()]]);
// Convert the CollectionInfoIterator to an array since we cannot rewind its cursor
$collections = iterator_to_array($operation->execute($server));
$this->assertCount(1, $collections);
foreach ($collections as $collection) {
$this->assertInstanceOf('MongoDB\Model\CollectionInfo', $collection);
$this->assertEquals($this->getCollectionName(), $collection->getName());
}
}
public function testListCollectionsForNonexistentDatabase()
{
$server = $this->getPrimaryServer();
$operation = new DropDatabase($this->getDatabaseName());
$operation->execute($server);
$operation = new ListCollections($this->getDatabaseName());
$collections = $operation->execute($server);
$this->assertCount(0, $collections);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment