Skip to content

Commit e5d0dd7

Browse files
committed
Add collection info and tests
1 parent 40058c7 commit e5d0dd7

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/Jenssegers/Mongodb/Schema/Builder.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ public function hasColumns($table, array $columns)
3434
/**
3535
* Determine if the given collection exists.
3636
* @param string $collection
37-
* @return bool
37+
* @param bool $collection_info
38+
* @return bool|\MongoDB\Model\CollectionInfo
3839
*/
39-
public function hasCollection($collection)
40+
public function hasCollection($collection, $collection_info = false)
4041
{
4142
$db = $this->connection->getMongoDB();
4243

4344
foreach ($db->listCollections() as $collectionFromMongo) {
4445
if ($collectionFromMongo->getName() == $collection) {
45-
return true;
46+
return $collection_info ? $collectionFromMongo : true;
4647
}
4748
}
4849

tests/SchemaTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public function testCreateWithOptions(): void
3434
Schema::create('newcollection_two', null, ['capped' => true, 'size' => 1024]);
3535
$this->assertTrue(Schema::hasCollection('newcollection_two'));
3636
$this->assertTrue(Schema::hasTable('newcollection_two'));
37+
38+
$collection = Schema::hasCollection('newcollection_two', true);
39+
$this->assertTrue($collection['options']['capped']);
40+
$this->assertEquals(1024, $collection['options']['size']);
3741
}
3842

3943
public function testDrop(): void

0 commit comments

Comments
 (0)