Commit 3b128d3a authored by Jeremy Mikola's avatar Jeremy Mikola

Merge pull request #70

parents cb5cf0bb fdaed29c
......@@ -5,8 +5,7 @@ namespace MongoDB\Operation;
use MongoDB\Driver\Command;
use MongoDB\Driver\Server;
use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnexpectedTypeException;
use MongoDB\Model\IndexInput;
use MongoDB\Exception\InvalidArgumentTypeException;
/**
* Operation for the create command.
......@@ -40,6 +39,9 @@ class CreateCollection implements Executable
* bitwise combination USE_POWER_OF_2_SIZES and NO_PADDING. The default
* is USE_POWER_OF_2_SIZES.
*
* * indexOptionDefaults (document): Default configuration for indexes when
* creating the collection.
*
* * max (integer): The maximum number of documents allowed in the capped
* collection. The size option takes precedence over this limit.
*
......@@ -70,6 +72,10 @@ class CreateCollection implements Executable
throw new InvalidArgumentTypeException('"flags" option', $options['flags'], 'integer');
}
if (isset($options['indexOptionDefaults']) && ! is_array($options['indexOptionDefaults']) && ! is_object($options['indexOptionDefaults'])) {
throw new InvalidArgumentTypeException('"indexOptionDefaults" option', $options['indexOptionDefaults'], 'array or object');
}
if (isset($options['max']) && ! is_integer($options['max'])) {
throw new InvalidArgumentTypeException('"max" option', $options['max'], 'integer');
}
......@@ -120,6 +126,10 @@ class CreateCollection implements Executable
}
}
if ( ! empty($this->options['indexOptionDefaults'])) {
$cmd['indexOptionDefaults'] = (object) $this->options['indexOptionDefaults'];
}
if ( ! empty($this->options['storageEngine'])) {
$cmd['storageEngine'] = (object) $this->options['storageEngine'];
}
......
<?php
namespace MongoDB\Tests\Operation;
use MongoDB\Operation\CreateCollection;
class CreateCollectionTest extends TestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidConstructorOptions
*/
public function testConstructorOptionTypeChecks(array $options)
{
new CreateCollection($this->getDatabaseName(), $this->getCollectionName(), $options);
}
public function provideInvalidConstructorOptions()
{
$options = [];
foreach ($this->getInvalidBooleanValues() as $value) {
$options[][] = ['autoIndexId' => $value];
}
foreach ($this->getInvalidBooleanValues() as $value) {
$options[][] = ['capped' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = ['flags' => $value];
}
foreach ($this->getInvalidDocumentValues() as $value) {
$options[][] = ['indexOptionDefaults' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = ['max' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = ['maxTimeMS' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = ['size' => $value];
}
foreach ($this->getInvalidDocumentValues() as $value) {
$options[][] = ['storageEngine' => $value];
}
return $options;
}
}
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