Skip to content

Commit f0be7e0

Browse files
committed
Test type validation for search index "type" option
1 parent 3f43876 commit f0be7e0

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

tests/Model/SearchIndexInputTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ public function testConstructorShouldRequireNameToBeString($name): void
3232
new SearchIndexInput(['definition' => ['mapping' => ['dynamic' => true]], 'name' => $name]);
3333
}
3434

35+
/** @dataProvider provideInvalidStringValues */
36+
public function testConstructorShouldRequireTypeToBeString($type): void
37+
{
38+
$this->expectException(InvalidArgumentException::class);
39+
$this->expectExceptionMessage('Expected "type" option to have type "string"');
40+
new SearchIndexInput(['definition' => ['mapping' => ['dynamic' => true]], 'type' => $type]);
41+
}
42+
3543
public function testBsonSerialization(): void
3644
{
3745
$expected = (object) [

tests/Operation/CreateSearchIndexesTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ public function testConstructorIndexNameMustBeAString($name): void
3030
new CreateSearchIndexes($this->getDatabaseName(), $this->getCollectionName(), [['name' => $name, 'definition' => ['mappings' => ['dynamic' => true]]]], []);
3131
}
3232

33+
/** @dataProvider provideInvalidStringValues */
34+
public function testConstructorIndexTypeMustBeAString($type): void
35+
{
36+
$this->expectException(InvalidArgumentException::class);
37+
$this->expectExceptionMessage('Expected "type" option to have type "string"');
38+
new CreateSearchIndexes($this->getDatabaseName(), $this->getCollectionName(), [['type' => $type, 'definition' => ['mappings' => ['dynamic' => true]]]], []);
39+
}
40+
3341
public function testConstructorIndexDefinitionMustBeDefined(): void
3442
{
3543
$this->expectException(InvalidArgumentException::class);

0 commit comments

Comments
 (0)