Skip to content

Commit 40c2744

Browse files
authored
Compatibility with MongoDB 5.0 (#2401)
* Add MongoDB 5.0 to test matrix * Ensure collMod.validator is an object
2 parents a935640 + 3ae453b commit 40c2744

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
- "8.0"
2424
- "8.1"
2525
mongodb-version:
26+
- "5.0"
2627
- "4.4"
2728
- "4.2"
2829
- "4.0"

lib/Doctrine/ODM/MongoDB/SchemaManager.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
use function array_unique;
2222
use function array_values;
2323
use function assert;
24+
use function count;
2425
use function in_array;
26+
use function is_array;
2527
use function is_string;
2628
use function iterator_count;
2729
use function iterator_to_array;
@@ -352,9 +354,9 @@ public function updateDocumentValidator(string $documentName, ?int $maxTimeMs =
352354
throw new InvalidArgumentException('Cannot update validators for files, views, mapped super classes, embedded documents or aggregation result documents.');
353355
}
354356

355-
$validator = [];
356-
if ($class->getValidator() !== null) {
357-
$validator = $class->getValidator();
357+
$validator = $class->getValidator();
358+
if ($validator === null || (is_array($validator) && count($validator) === 0)) {
359+
$validator = (object) [];
358360
}
359361

360362
$collection = $this->dm->getDocumentCollection($class->name);

tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ public function testUpdateDocumentValidatorReset(array $expectedWriteOptions, ?i
472472
->with(
473473
[
474474
'collMod' => $class->collection,
475-
'validator' => [],
475+
'validator' => (object) [],
476476
'validationAction' => ClassMetadata::SCHEMA_VALIDATION_ACTION_ERROR,
477477
'validationLevel' => ClassMetadata::SCHEMA_VALIDATION_LEVEL_STRICT,
478478
],

0 commit comments

Comments
 (0)