Skip to content

Commit 38b6851

Browse files
committed
PHPLIB-591: CreateIndexes should not specify "ns" for index specifications
Also adds an extra option to the BSON serialization test.
1 parent b35af66 commit 38b6851

File tree

3 files changed

+5
-29
lines changed

3 files changed

+5
-29
lines changed

src/Model/IndexInput.php

-8
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,6 @@ public function __construct(array $index)
6262
}
6363
}
6464

65-
if (! isset($index['ns'])) {
66-
throw new InvalidArgumentException('Required "ns" option is missing from index specification');
67-
}
68-
69-
if (! is_string($index['ns'])) {
70-
throw InvalidArgumentException::invalidType('"ns" option', $index['ns'], 'string');
71-
}
72-
7365
if (! isset($index['name'])) {
7466
$index['name'] = generate_index_name($index['key']);
7567
}

src/Operation/CreateIndexes.php

-4
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ public function __construct($databaseName, $collectionName, array $indexes, arra
110110
throw InvalidArgumentException::invalidType(sprintf('$index[%d]', $i), $index, 'array');
111111
}
112112

113-
if (! isset($index['ns'])) {
114-
$index['ns'] = $databaseName . '.' . $collectionName;
115-
}
116-
117113
if (isset($index['collation'])) {
118114
$this->isCollationUsed = true;
119115
}

tests/Model/IndexInputTest.php

+5-17
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,18 @@ public function provideInvalidFieldOrderValues()
3636
return $this->wrapValuesForDataProvider([true, [], new stdClass()]);
3737
}
3838

39-
public function testConstructorShouldRequireNamespace()
40-
{
41-
$this->expectException(InvalidArgumentException::class);
42-
new IndexInput(['key' => ['x' => 1]]);
43-
}
44-
45-
public function testConstructorShouldRequireNamespaceToBeString()
46-
{
47-
$this->expectException(InvalidArgumentException::class);
48-
new IndexInput(['key' => ['x' => 1], 'ns' => 1]);
49-
}
50-
5139
public function testConstructorShouldRequireNameToBeString()
5240
{
5341
$this->expectException(InvalidArgumentException::class);
54-
new IndexInput(['key' => ['x' => 1], 'ns' => 'foo.bar', 'name' => 1]);
42+
new IndexInput(['key' => ['x' => 1], 'name' => 1]);
5543
}
5644

5745
/**
5846
* @dataProvider provideExpectedNameAndKey
5947
*/
6048
public function testNameGeneration($expectedName, array $key)
6149
{
62-
$this->assertSame($expectedName, (string) new IndexInput(['key' => $key, 'ns' => 'foo.bar']));
50+
$this->assertSame($expectedName, (string) new IndexInput(['key' => $key]));
6351
}
6452

6553
public function provideExpectedNameAndKey()
@@ -77,16 +65,16 @@ public function testBsonSerialization()
7765
{
7866
$expected = [
7967
'key' => ['x' => 1],
80-
'ns' => 'foo.bar',
68+
'unique' => true,
8169
'name' => 'x_1',
8270
];
8371

8472
$indexInput = new IndexInput([
8573
'key' => ['x' => 1],
86-
'ns' => 'foo.bar',
74+
'unique' => true,
8775
]);
8876

8977
$this->assertInstanceOf(Serializable::class, $indexInput);
90-
$this->assertEquals($expected, $indexInput->bsonSerialize());
78+
$this->assertSame($expected, $indexInput->bsonSerialize());
9179
}
9280
}

0 commit comments

Comments
 (0)