From d2b74fce3de8c686f52c73451cbc2396bef96d4d Mon Sep 17 00:00:00 2001 From: Maciej Malarz Date: Tue, 28 Dec 2021 00:13:37 +0100 Subject: [PATCH 1/2] Add MongoDB 5.0 to test matrix --- .github/workflows/continuous-integration.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 15a935264e..7ac91438d2 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -23,6 +23,7 @@ jobs: - "8.0" - "8.1" mongodb-version: + - "5.0" - "4.4" - "4.2" - "4.0" From 3ae453b9cf948f71d2b9721cbf31b25b441782de Mon Sep 17 00:00:00 2001 From: Maciej Malarz Date: Tue, 28 Dec 2021 00:39:48 +0100 Subject: [PATCH 2/2] Ensure collMod.validator is an object --- lib/Doctrine/ODM/MongoDB/SchemaManager.php | 8 +++++--- tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ODM/MongoDB/SchemaManager.php b/lib/Doctrine/ODM/MongoDB/SchemaManager.php index a8700c695b..77ce9aaf4d 100644 --- a/lib/Doctrine/ODM/MongoDB/SchemaManager.php +++ b/lib/Doctrine/ODM/MongoDB/SchemaManager.php @@ -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; @@ -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); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php b/tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php index d09b8603b6..ab3141fe1a 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php @@ -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, ],