Commit 67c450b9 authored by Will Banfield's avatar Will Banfield Committed by Jeremy Mikola

PHPLIB-160: implement drop() on bucket

parent 6aa739c4
...@@ -150,6 +150,16 @@ class Bucket ...@@ -150,6 +150,16 @@ class Bucket
$gridFsStream->downloadToStream($destination); $gridFsStream->downloadToStream($destination);
} }
/**
* Drops the files and chunks collection associated with GridFS this bucket
*
*/
public function drop()
{
$this->collectionsWrapper->dropCollections();
}
/** /**
* Find files from the GridFS bucket's files collection. * Find files from the GridFS bucket's files collection.
* *
......
...@@ -10,7 +10,7 @@ use MongoDB\Exception\InvalidArgumentTypeException; ...@@ -10,7 +10,7 @@ use MongoDB\Exception\InvalidArgumentTypeException;
/** /**
* GridFSCollectionsWrapper abstracts the GridFS files and chunks collections. * GridFSCollectionsWrapper abstracts the GridFS files and chunks collections.
* *
* @internal * @internal
*/ */
class GridFSCollectionsWrapper class GridFSCollectionsWrapper
...@@ -35,6 +35,11 @@ class GridFSCollectionsWrapper ...@@ -35,6 +35,11 @@ class GridFSCollectionsWrapper
$this->chunksCollection = new Collection($manager, sprintf('%s.%s.chunks', $databaseName, $bucketName), $collectionOptions); $this->chunksCollection = new Collection($manager, sprintf('%s.%s.chunks', $databaseName, $bucketName), $collectionOptions);
} }
public function dropCollections(){
$this->filesCollection-> drop();
$this->chunksCollection->drop();
}
public function getChunksCollection() public function getChunksCollection()
{ {
return $this->chunksCollection; return $this->chunksCollection;
......
...@@ -273,6 +273,13 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -273,6 +273,13 @@ class BucketFunctionalTest extends FunctionalTestCase
$this->assertEquals("testing", stream_get_contents($this->bucket->openDownloadStreamByName("second_name"))); $this->assertEquals("testing", stream_get_contents($this->bucket->openDownloadStreamByName("second_name")));
} }
public function testDrop()
{
$id = $this->bucket->uploadFromStream("test_filename", $this->generateStream("hello world"));
$this->bucket->drop();
$id = $this->bucket->uploadFromStream("test_filename", $this->generateStream("hello world"));
$this->assertEquals(1, $this->collectionsWrapper->getFilesCollection()->count());
}
/** /**
*@dataProvider provideInsertChunks *@dataProvider provideInsertChunks
*/ */
......
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