Commit 6b950169 authored by Jeremy Mikola's avatar Jeremy Mikola

CreateIndexes can require that $indexes be a list

parent 7239ab74
......@@ -40,7 +40,13 @@ class CreateIndexes implements Executable
throw new InvalidArgumentException('$indexes is empty');
}
foreach ($indexes as $index) {
$expectedIndex = 0;
foreach ($indexes as $i => $index) {
if ($i !== $expectedIndex) {
throw new InvalidArgumentException(sprintf('$indexes is not a list (unexpected index: "%s")', $i));
}
if ( ! is_array($index)) {
throw new InvalidArgumentTypeException(sprintf('$index[%d]', $i), $index, 'array');
}
......@@ -50,6 +56,8 @@ class CreateIndexes implements Executable
}
$this->indexes[] = new IndexInput($index);
$expectedIndex += 1;
}
$this->databaseName = (string) $databaseName;
......
......@@ -16,7 +16,16 @@ class CreateIndexesTest extends TestCase
}
/**
* @expectedException MongoDB\Exception\UnexpectedTypeException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedExceptionMessage $indexes is not a list (unexpected index: "1")
*/
public function testConstructorIndexesArgumentMustBeAList()
{
new CreateIndexes($this->getDatabaseName(), $this->getCollectionName(), [1 => ['key' => ['x' => 1]]]);
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidIndexSpecificationTypes
*/
public function testCreateIndexesRequiresIndexSpecificationsToBeAnArray($index)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment