Skip to content

Commit 9d7f8e6

Browse files
committed
Merge pull request #74
Please enter a commit message to explain why this merge is necessary,
2 parents 28e0574 + 329ed9c commit 9d7f8e6

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/Operation/CreateCollection.php

+26-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@ class CreateCollection implements Executable
5252
*
5353
* * storageEngine (document): Storage engine options.
5454
*
55+
* * validationAction (string): Validation action.
56+
*
57+
* * validationLevel (string): Validation level.
58+
*
59+
* * validator (document): Validation rules or expressions.
60+
*
5561
* @see http://source.wiredtiger.com/2.4.1/struct_w_t___s_e_s_s_i_o_n.html#a358ca4141d59c345f401c58501276bbb
62+
* @see https://docs.mongodb.org/manual/core/document-validation/
5663
* @param string $databaseName Database name
5764
* @param string $collectionName Collection name
5865
* @param array $options Command options
@@ -92,6 +99,18 @@ public function __construct($databaseName, $collectionName, array $options = [])
9299
throw new InvalidArgumentTypeException('"storageEngine" option', $options['storageEngine'], 'array or object');
93100
}
94101

102+
if (isset($options['validationAction']) && ! is_string($options['validationAction'])) {
103+
throw new InvalidArgumentTypeException('"validationAction" option', $options['validationAction'], 'string');
104+
}
105+
106+
if (isset($options['validationLevel']) && ! is_string($options['validationLevel'])) {
107+
throw new InvalidArgumentTypeException('"validationLevel" option', $options['validationLevel'], 'string');
108+
}
109+
110+
if (isset($options['validator']) && ! is_array($options['validator']) && ! is_object($options['validator'])) {
111+
throw new InvalidArgumentTypeException('"validator" option', $options['validator'], 'array or object');
112+
}
113+
95114
$this->databaseName = (string) $databaseName;
96115
$this->collectionName = (string) $collectionName;
97116
$this->options = $options;
@@ -120,20 +139,24 @@ private function createCommand()
120139
{
121140
$cmd = ['create' => $this->collectionName];
122141

123-
foreach (['autoIndexId', 'capped', 'flags', 'max', 'maxTimeMS', 'size'] as $option) {
142+
foreach (['autoIndexId', 'capped', 'flags', 'max', 'maxTimeMS', 'size', 'validationAction', 'validationLevel'] as $option) {
124143
if (isset($this->options[$option])) {
125144
$cmd[$option] = $this->options[$option];
126145
}
127146
}
128147

129-
if ( ! empty($this->options['indexOptionDefaults'])) {
148+
if (isset($this->options['indexOptionDefaults'])) {
130149
$cmd['indexOptionDefaults'] = (object) $this->options['indexOptionDefaults'];
131150
}
132151

133-
if ( ! empty($this->options['storageEngine'])) {
152+
if (isset($this->options['storageEngine'])) {
134153
$cmd['storageEngine'] = (object) $this->options['storageEngine'];
135154
}
136155

156+
if (isset($this->options['validator'])) {
157+
$cmd['validator'] = (object) $this->options['validator'];
158+
}
159+
137160
return new Command($cmd);
138161
}
139162
}

tests/Operation/CreateCollectionTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ public function provideInvalidConstructorOptions()
5151
$options[][] = ['storageEngine' => $value];
5252
}
5353

54+
foreach ($this->getInvalidStringValues() as $value) {
55+
$options[][] = ['validationAction' => $value];
56+
}
57+
58+
foreach ($this->getInvalidStringValues() as $value) {
59+
$options[][] = ['validationLevel' => $value];
60+
}
61+
62+
foreach ($this->getInvalidDocumentValues() as $value) {
63+
$options[][] = ['validator' => $value];
64+
}
65+
5466
return $options;
5567
}
5668
}

0 commit comments

Comments
 (0)