|
10 | 10 | use function MongoDB\generate_index_name;
|
11 | 11 | use function MongoDB\is_first_key_operator;
|
12 | 12 | use function MongoDB\is_mapreduce_output_inline;
|
| 13 | +use function MongoDB\is_pipeline; |
13 | 14 |
|
14 | 15 | /**
|
15 | 16 | * Unit tests for utility functions.
|
@@ -224,4 +225,33 @@ public function provideTypeMapValues()
|
224 | 225 | ],
|
225 | 226 | ];
|
226 | 227 | }
|
| 228 | + |
| 229 | + /** |
| 230 | + * @dataProvider providePipelines |
| 231 | + */ |
| 232 | + public function testIsPipeline($expected, $pipeline) |
| 233 | + { |
| 234 | + $this->assertSame($expected, is_pipeline($pipeline)); |
| 235 | + } |
| 236 | + |
| 237 | + public function providePipelines() |
| 238 | + { |
| 239 | + return [ |
| 240 | + 'Not an array' => [false, (object) []], |
| 241 | + 'Empty array' => [false, []], |
| 242 | + 'Non-sequential indexes in array' => [false, [1 => ['$group' => []]]], |
| 243 | + 'Update document instead of pipeline' => [false, ['$set' => ['foo' => 'bar']]], |
| 244 | + 'Invalid pipeline stage' => [false, [['group' => []]]], |
| 245 | + 'Update with DbRef' => [false, ['x' => ['$ref' => 'foo', '$id' => 'bar']]], |
| 246 | + 'Valid pipeline' => [ |
| 247 | + true, |
| 248 | + [ |
| 249 | + ['$match' => ['foo' => 'bar']], |
| 250 | + ['$group' => ['_id' => 1]], |
| 251 | + ], |
| 252 | + ], |
| 253 | + 'False positive with DbRef in numeric field' => [true, ['0' => ['$ref' => 'foo', '$id' => 'bar']]], |
| 254 | + 'DbRef in numeric field as object' => [false, (object) ['0' => ['$ref' => 'foo', '$id' => 'bar']]], |
| 255 | + ]; |
| 256 | + } |
227 | 257 | }
|
0 commit comments