Skip to content

Commit

Permalink
Ensure collMod.validator is an object
Browse files Browse the repository at this point in the history
  • Loading branch information
malarzm committed Dec 27, 2021
1 parent d2b74fc commit 3ae453b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/Doctrine/ODM/MongoDB/SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
use function array_unique;
use function array_values;
use function assert;
use function count;
use function in_array;
use function is_array;
use function is_string;
use function iterator_count;
use function iterator_to_array;
Expand Down Expand Up @@ -352,9 +354,9 @@ public function updateDocumentValidator(string $documentName, ?int $maxTimeMs =
throw new InvalidArgumentException('Cannot update validators for files, views, mapped super classes, embedded documents or aggregation result documents.');
}

$validator = [];
if ($class->getValidator() !== null) {
$validator = $class->getValidator();
$validator = $class->getValidator();
if ($validator === null || (is_array($validator) && count($validator) === 0)) {
$validator = (object) [];
}

$collection = $this->dm->getDocumentCollection($class->name);
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public function testUpdateDocumentValidatorReset(array $expectedWriteOptions, ?i
->with(
[
'collMod' => $class->collection,
'validator' => [],
'validator' => (object) [],
'validationAction' => ClassMetadata::SCHEMA_VALIDATION_ACTION_ERROR,
'validationLevel' => ClassMetadata::SCHEMA_VALIDATION_LEVEL_STRICT,
],
Expand Down

0 comments on commit 3ae453b

Please sign in to comment.