diff --git a/src/Model/CollectionInfo.php b/src/Model/CollectionInfo.php index 717e19d84..a9fe97b04 100644 --- a/src/Model/CollectionInfo.php +++ b/src/Model/CollectionInfo.php @@ -130,6 +130,14 @@ public function isCapped(): bool return ! empty($this->info['options']['capped']); } + /** + * Determines whether the collection is a view. + */ + public function isView(): bool + { + return $this->getType() === 'view'; + } + /** * Check whether a field exists in the collection information. * diff --git a/tests/Model/CollectionInfoTest.php b/tests/Model/CollectionInfoTest.php index 043023baa..9b926cfad 100644 --- a/tests/Model/CollectionInfoTest.php +++ b/tests/Model/CollectionInfoTest.php @@ -10,7 +10,7 @@ class CollectionInfoTest extends TestCase { public function testGetBasicInformation(): void { - $info = new CollectionInfo([ + $viewInfo = new CollectionInfo([ 'name' => 'foo', 'type' => 'view', 'options' => ['capped' => true, 'size' => 1_048_576], @@ -18,20 +18,27 @@ public function testGetBasicInformation(): void 'idIndex' => ['idIndex' => true], // Dummy option ]); - $this->assertSame('foo', $info->getName()); - $this->assertSame('foo', $info['name']); + $this->assertSame('foo', $viewInfo->getName()); + $this->assertSame('foo', $viewInfo['name']); + + $this->assertTrue($viewInfo->isView()); + $this->assertSame('view', $viewInfo['type']); - $this->assertSame('view', $info->getType()); - $this->assertSame('view', $info['type']); + $this->assertSame(['capped' => true, 'size' => 1_048_576], $viewInfo->getOptions()); + $this->assertSame(['capped' => true, 'size' => 1_048_576], $viewInfo['options']); - $this->assertSame(['capped' => true, 'size' => 1_048_576], $info->getOptions()); - $this->assertSame(['capped' => true, 'size' => 1_048_576], $info['options']); + $this->assertSame(['readOnly' => true], $viewInfo->getInfo()); + $this->assertSame(['readOnly' => true], $viewInfo['info']); - $this->assertSame(['readOnly' => true], $info->getInfo()); - $this->assertSame(['readOnly' => true], $info['info']); + $this->assertSame(['idIndex' => true], $viewInfo->getIdIndex()); + $this->assertSame(['idIndex' => true], $viewInfo['idIndex']); + + $collectionInfo = new CollectionInfo([ + 'name' => 'bar', + 'type' => 'collection', + ]); - $this->assertSame(['idIndex' => true], $info->getIdIndex()); - $this->assertSame(['idIndex' => true], $info['idIndex']); + $this->assertFalse($collectionInfo->isView()); } public function testMissingFields(): void