Commit 28da2e1e authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-71: Collection drop methods

parent 6c1d6ac1
......@@ -334,11 +334,15 @@ class Collection
/**
* Drop this collection.
*
* @see http://docs.mongodb.org/manual/reference/command/drop/
* @return Result
*/
public function drop()
{
// TODO
$command = new Command(array('drop' => $this->collname));
$readPreference = new ReadPreference(ReadPreference::RP_PRIMARY);
return $this->manager->executeCommand($this->dbname, $command, $readPreference);
}
/**
......
......@@ -66,12 +66,17 @@ class Database
/**
* Drop a collection within this database.
*
* @see http://docs.mongodb.org/manual/reference/command/drop/
* @param string $collectionName
* @return Result
*/
public function dropCollection($collectionName)
{
// TODO
$collectionName = (string) $collectionName;
$command = new Command(array('drop' => $collectionName));
$readPreference = new ReadPreference(ReadPreference::RP_PRIMARY);
return $this->manager->executeCommand($this->databaseName, $command, $readPreference);
}
/**
......
......@@ -17,6 +17,16 @@ class CollectionFunctionalTest extends FunctionalTestCase
$this->collection->deleteMany(array());
}
public function testDrop()
{
$writeResult = $this->collection->insertOne(array('x' => 1));
$this->assertEquals(1, $writeResult->getInsertedCount());
$commandResult = $this->collection->drop();
$this->assertCommandSucceeded($commandResult);
$this->assertCollectionCount($this->getNamespace(), 0);
}
function testInsertAndRetrieve()
{
$generator = new FixtureGenerator();
......
......@@ -20,4 +20,15 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this->assertCommandSucceeded($commandResult);
$this->assertCollectionCount($this->getNamespace(), 0);
}
public function testDropCollection()
{
$writeResult = $this->manager->executeInsert($this->getNamespace(), array('x' => 1));
$this->assertEquals(1, $writeResult->getInsertedCount());
$database = new Database($this->manager, $this->getDatabaseName());
$commandResult = $database->dropCollection($this->getCollectionName());
$this->assertCommandSucceeded($commandResult);
$this->assertCollectionCount($this->getNamespace(), 0);
}
}
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