Commit e5d0dd71 authored by Ditty's avatar Ditty

Add collection info and tests

parent 40058c75
......@@ -34,15 +34,16 @@ class Builder extends \Illuminate\Database\Schema\Builder
/**
* Determine if the given collection exists.
* @param string $collection
* @return bool
* @param bool $collection_info
* @return bool|\MongoDB\Model\CollectionInfo
*/
public function hasCollection($collection)
public function hasCollection($collection, $collection_info = false)
{
$db = $this->connection->getMongoDB();
foreach ($db->listCollections() as $collectionFromMongo) {
if ($collectionFromMongo->getName() == $collection) {
return true;
return $collection_info ? $collectionFromMongo : true;
}
}
......
......@@ -34,6 +34,10 @@ class SchemaTest extends TestCase
Schema::create('newcollection_two', null, ['capped' => true, 'size' => 1024]);
$this->assertTrue(Schema::hasCollection('newcollection_two'));
$this->assertTrue(Schema::hasTable('newcollection_two'));
$collection = Schema::hasCollection('newcollection_two', true);
$this->assertTrue($collection['options']['capped']);
$this->assertEquals(1024, $collection['options']['size']);
}
public function testDrop(): void
......
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