|
12 | 12 | use MongoDB\Collection;
|
13 | 13 | use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
|
14 | 14 | use MongoDB\Model\BSONDocument;
|
| 15 | +use MongoDB\Model\BSONArray; |
15 | 16 | use MongoDB\Model\IndexInfoIteratorIterator;
|
16 | 17 | use MongoDB\Operation\FindOneAndUpdate;
|
17 | 18 | use PHPUnit\Framework\Constraint\Constraint;
|
@@ -234,7 +235,6 @@ private function updateCore(&$doc, $update)
|
234 | 235 | $doc[$k][] = $v;
|
235 | 236 | }
|
236 | 237 | }
|
237 |
| - |
238 | 238 | }
|
239 | 239 |
|
240 | 240 | public function find($filter = [], array $options = []): MockCursor
|
@@ -377,7 +377,7 @@ public function deleteOne($filter, array $options = [])
|
377 | 377 | $deletedIds = [];
|
378 | 378 | foreach ($this->documents as $i => $doc) {
|
379 | 379 | if ($matcher($doc)) {
|
380 |
| - $deletedIds [] = $doc['_id']; |
| 380 | + $deletedIds[] = $doc['_id']; |
381 | 381 | unset($this->documents[$i]);
|
382 | 382 | $this->documents = array_values($this->documents);
|
383 | 383 | $count++;
|
@@ -613,8 +613,18 @@ private function matcherFromConstraint($constraint): callable
|
613 | 613 |
|
614 | 614 | if (is_array($constraint)) {
|
615 | 615 | return $match = function ($val) use (&$constraint, &$match): bool {
|
| 616 | + //cast $val to array if it is an instance of BSONArray |
| 617 | + //this will prevent is_array,array_reduce... from failing |
| 618 | + if ($val instanceof BSONArray) { |
| 619 | + $val = (array)$val; |
| 620 | + } |
616 | 621 | $result = true;
|
617 | 622 | foreach ($constraint as $type => $operand) {
|
| 623 | + //cast $operand to array if it is an instance of BSONArray |
| 624 | + //this will prevent is_array,array_reduce... from failing |
| 625 | + if ($operand instanceof BSONArray) { |
| 626 | + $operand = (array)$operand; |
| 627 | + } |
618 | 628 | switch ($type) {
|
619 | 629 | // Mongo operators (subset)
|
620 | 630 | case '$gt':
|
|
0 commit comments