Skip to content

Commit 1972255

Browse files
authored
Add CollectionInfo::isView (#1727)
To provide a more convenient way of determining if a collection is a view.
1 parent 37440db commit 1972255

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

src/Model/CollectionInfo.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ public function isCapped(): bool
130130
return ! empty($this->info['options']['capped']);
131131
}
132132

133+
/**
134+
* Determines whether the collection is a view.
135+
*/
136+
public function isView(): bool
137+
{
138+
return $this->getType() === 'view';
139+
}
140+
133141
/**
134142
* Check whether a field exists in the collection information.
135143
*

tests/Model/CollectionInfoTest.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,35 @@ class CollectionInfoTest extends TestCase
1010
{
1111
public function testGetBasicInformation(): void
1212
{
13-
$info = new CollectionInfo([
13+
$viewInfo = new CollectionInfo([
1414
'name' => 'foo',
1515
'type' => 'view',
1616
'options' => ['capped' => true, 'size' => 1_048_576],
1717
'info' => ['readOnly' => true],
1818
'idIndex' => ['idIndex' => true], // Dummy option
1919
]);
2020

21-
$this->assertSame('foo', $info->getName());
22-
$this->assertSame('foo', $info['name']);
21+
$this->assertSame('foo', $viewInfo->getName());
22+
$this->assertSame('foo', $viewInfo['name']);
23+
24+
$this->assertTrue($viewInfo->isView());
25+
$this->assertSame('view', $viewInfo['type']);
2326

24-
$this->assertSame('view', $info->getType());
25-
$this->assertSame('view', $info['type']);
27+
$this->assertSame(['capped' => true, 'size' => 1_048_576], $viewInfo->getOptions());
28+
$this->assertSame(['capped' => true, 'size' => 1_048_576], $viewInfo['options']);
2629

27-
$this->assertSame(['capped' => true, 'size' => 1_048_576], $info->getOptions());
28-
$this->assertSame(['capped' => true, 'size' => 1_048_576], $info['options']);
30+
$this->assertSame(['readOnly' => true], $viewInfo->getInfo());
31+
$this->assertSame(['readOnly' => true], $viewInfo['info']);
2932

30-
$this->assertSame(['readOnly' => true], $info->getInfo());
31-
$this->assertSame(['readOnly' => true], $info['info']);
33+
$this->assertSame(['idIndex' => true], $viewInfo->getIdIndex());
34+
$this->assertSame(['idIndex' => true], $viewInfo['idIndex']);
35+
36+
$collectionInfo = new CollectionInfo([
37+
'name' => 'bar',
38+
'type' => 'collection',
39+
]);
3240

33-
$this->assertSame(['idIndex' => true], $info->getIdIndex());
34-
$this->assertSame(['idIndex' => true], $info['idIndex']);
41+
$this->assertFalse($collectionInfo->isView());
3542
}
3643

3744
public function testMissingFields(): void

0 commit comments

Comments
 (0)