Commit 3f12bc6a authored by Jeremy Mikola's avatar Jeremy Mikola

DropDatabase functional tests

parent cf351325
<?php
namespace MongoDB\Tests\Operation;
use MongoDB\Driver\Server;
use MongoDB\Operation\DropDatabase;
use MongoDB\Operation\ListDatabases;
class DropDatabaseFunctionalTest extends FunctionalTestCase
{
public function testDropExistingDatabase()
{
$writeResult = $this->manager->executeInsert($this->getNamespace(), array('x' => 1));
$this->assertEquals(1, $writeResult->getInsertedCount());
$server = $this->getPrimaryServer();
$operation = new DropDatabase($this->getDatabaseName());
$operation->execute($server);
$this->assertDatabaseDoesNotExist($server, $this->getDatabaseName());
}
/**
* @depends testDropExistingDatabase
*/
public function testDropNonexistentDatabase()
{
$server = $this->getPrimaryServer();
$this->assertDatabaseDoesNotExist($server, $this->getDatabaseName());
$operation = new DropDatabase($this->getDatabaseName());
$operation->execute($server);
}
/**
* Asserts that a database with the given name does not exist on the server.
*
* @param Server $server
* @param string $databaseName
*/
private function assertDatabaseDoesNotExist(Server $server, $databaseName)
{
$operation = new ListDatabases();
$databases = $operation->execute($server);
$foundDatabase = null;
foreach ($databases as $database) {
if ($database->getName() === $databaseName) {
$foundDatabase = $database;
break;
}
}
$this->assertNull($foundDatabase, sprintf('Database %s exists on the server', $databaseName));
}
}
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