Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Model/CollectionInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
29 changes: 18 additions & 11 deletions tests/Model/CollectionInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,35 @@ 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],
'info' => ['readOnly' => true],
'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
Expand Down