diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php index 2efd7edd4..07be585af 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php @@ -393,6 +393,7 @@ private function addEmbedMapping(ClassMetadata $class, SimpleXMLElement $embed, 'name' => (string) $attributes['field'], 'strategy' => (string) ($attributes['strategy'] ?? $defaultStrategy), 'nullable' => isset($attributes['nullable']) ? ((string) $attributes['nullable'] === 'true') : false, + 'storeEmptyArray' => isset($attributes['store-empty-array']) ? ((string) $attributes['store-empty-array'] === 'true') : false, ]; if (isset($attributes['field-name'])) { $mapping['fieldName'] = (string) $attributes['field-name']; diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractMappingDriverTestCase.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractMappingDriverTestCase.php index cb8b3507e..d13554156 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractMappingDriverTestCase.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/AbstractMappingDriverTestCase.php @@ -439,6 +439,17 @@ public function testShardKey(ClassMetadata $class): void self::assertEquals(4096, $shardKey['options']['numInitialChunks'], 'Shard key option has wrong value'); } + /** @param ClassMetadata $class */ + #[Depends('testLoadMapping')] + public function testStoreEmptyArray(ClassMetadata $class): void + { + $referenceMapping = $class->getFieldMapping('phonenumbers'); + $embeddedMapping = $class->getFieldMapping('otherPhonenumbers'); + + self::assertFalse($referenceMapping['storeEmptyArray']); + self::assertFalse($embeddedMapping['storeEmptyArray']); + } + public function testGridFSMapping(): void { $class = $this->dm->getClassMetadata(AbstractMappingDriverFile::class); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/AbstractDriverTestCase.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/AbstractDriverTestCase.php index 42833c917..ca7061a22 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/AbstractDriverTestCase.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/AbstractDriverTestCase.php @@ -125,6 +125,7 @@ public function testDriver(): void 'isOwningSide' => true, 'nullable' => false, 'strategy' => ClassMetadata::STORAGE_STRATEGY_SET, + 'storeEmptyArray' => false, ], $classMetadata->fieldMappings['address']); self::assertEquals([ @@ -144,6 +145,7 @@ public function testDriver(): void 'isOwningSide' => true, 'nullable' => false, 'strategy' => ClassMetadata::STORAGE_STRATEGY_PUSH_ALL, + 'storeEmptyArray' => false, ], $classMetadata->fieldMappings['phonenumbers']); self::assertEquals([ @@ -439,6 +441,7 @@ public function testNullableFieldsMapping(): void 'isOwningSide' => true, 'nullable' => true, 'strategy' => ClassMetadata::STORAGE_STRATEGY_SET, + 'storeEmptyArray' => false, ], $classMetadata->fieldMappings['address']); self::assertEquals([ @@ -458,6 +461,7 @@ public function testNullableFieldsMapping(): void 'isOwningSide' => true, 'nullable' => true, 'strategy' => ClassMetadata::STORAGE_STRATEGY_PUSH_ALL, + 'storeEmptyArray' => false, ], $classMetadata->fieldMappings['phonenumbers']); self::assertEquals([