diff --git a/src/Model/IndexInput.php b/src/Model/IndexInput.php index ca85ccab9..d7ec50fc2 100644 --- a/src/Model/IndexInput.php +++ b/src/Model/IndexInput.php @@ -62,14 +62,6 @@ public function __construct(array $index) } } - if (! isset($index['ns'])) { - throw new InvalidArgumentException('Required "ns" option is missing from index specification'); - } - - if (! is_string($index['ns'])) { - throw InvalidArgumentException::invalidType('"ns" option', $index['ns'], 'string'); - } - if (! isset($index['name'])) { $index['name'] = generate_index_name($index['key']); } diff --git a/src/Operation/CreateIndexes.php b/src/Operation/CreateIndexes.php index 3865080fc..ba53d95b7 100644 --- a/src/Operation/CreateIndexes.php +++ b/src/Operation/CreateIndexes.php @@ -110,10 +110,6 @@ public function __construct($databaseName, $collectionName, array $indexes, arra throw InvalidArgumentException::invalidType(sprintf('$index[%d]', $i), $index, 'array'); } - if (! isset($index['ns'])) { - $index['ns'] = $databaseName . '.' . $collectionName; - } - if (isset($index['collation'])) { $this->isCollationUsed = true; } diff --git a/tests/Model/IndexInputTest.php b/tests/Model/IndexInputTest.php index f6a7f8c5d..da6876169 100644 --- a/tests/Model/IndexInputTest.php +++ b/tests/Model/IndexInputTest.php @@ -36,22 +36,10 @@ public function provideInvalidFieldOrderValues() return $this->wrapValuesForDataProvider([true, [], new stdClass()]); } - public function testConstructorShouldRequireNamespace() - { - $this->expectException(InvalidArgumentException::class); - new IndexInput(['key' => ['x' => 1]]); - } - - public function testConstructorShouldRequireNamespaceToBeString() - { - $this->expectException(InvalidArgumentException::class); - new IndexInput(['key' => ['x' => 1], 'ns' => 1]); - } - public function testConstructorShouldRequireNameToBeString() { $this->expectException(InvalidArgumentException::class); - new IndexInput(['key' => ['x' => 1], 'ns' => 'foo.bar', 'name' => 1]); + new IndexInput(['key' => ['x' => 1], 'name' => 1]); } /** @@ -59,7 +47,7 @@ public function testConstructorShouldRequireNameToBeString() */ public function testNameGeneration($expectedName, array $key) { - $this->assertSame($expectedName, (string) new IndexInput(['key' => $key, 'ns' => 'foo.bar'])); + $this->assertSame($expectedName, (string) new IndexInput(['key' => $key])); } public function provideExpectedNameAndKey() @@ -77,16 +65,16 @@ public function testBsonSerialization() { $expected = [ 'key' => ['x' => 1], - 'ns' => 'foo.bar', + 'unique' => true, 'name' => 'x_1', ]; $indexInput = new IndexInput([ 'key' => ['x' => 1], - 'ns' => 'foo.bar', + 'unique' => true, ]); $this->assertInstanceOf(Serializable::class, $indexInput); - $this->assertEquals($expected, $indexInput->bsonSerialize()); + $this->assertSame($expected, $indexInput->bsonSerialize()); } }