diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index b677c0816dc..52d1d37f09a 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1056,9 +1056,19 @@ public function wakeupReflection($reflService) foreach ($this->fieldMappings as $field => $mapping) { if (isset($mapping['declaredField']) && isset($parentReflFields[$mapping['declaredField']])) { + $childProperty = $this->getAccessibleProperty($reflService, $mapping['originalClass'], $mapping['originalField']); + assert($childProperty !== null); + + if (isset($mapping['enumType'])) { + $childProperty = new ReflectionEnumProperty( + $childProperty, + $mapping['enumType'] + ); + } + $this->reflFields[$field] = new ReflectionEmbeddedProperty( $parentReflFields[$mapping['declaredField']], - $this->getAccessibleProperty($reflService, $mapping['originalClass'], $mapping['originalField']), + $childProperty, $mapping['originalClass'] ); continue; diff --git a/phpcs.xml.dist b/phpcs.xml.dist index d598ac25c4c..a75e6bd0a49 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -269,9 +269,11 @@ tests/Doctrine/Tests/Models/Enums/Suit.php + tests/Doctrine/Tests/Models/Enums/Unit.php tests/Doctrine/Tests/Models/Enums/Suit.php + tests/Doctrine/Tests/Models/Enums/Unit.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 7567e69a26a..d31f4564662 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -763,7 +763,7 @@ $fieldName $fieldName - + $class $className $entityResult['entityClass'] @@ -772,7 +772,6 @@ $parentReflFields[$embeddedClass['declaredField']] $parentReflFields[$mapping['declaredField']] $queryMapping['resultClass'] - $this->getAccessibleProperty($reflService, $mapping['originalClass'], $mapping['originalField']) $embeddable->reflClass->name diff --git a/tests/Doctrine/Tests/Models/Enums/Product.php b/tests/Doctrine/Tests/Models/Enums/Product.php new file mode 100644 index 00000000000..03f485353d3 --- /dev/null +++ b/tests/Doctrine/Tests/Models/Enums/Product.php @@ -0,0 +1,21 @@ +assertCount(1, $attributes); $this->assertEquals(Column::class, $attributes[0]->getName()); } + + public function testEnumMappingWithEmbeddable(): void + { + $this->setUpEntitySchema([Product::class]); + + $product = new Product(); + $product->quantity = new Quantity(); + $product->quantity->value = 10; + $product->quantity->unit = Unit::Gram; + + $this->_em->persist($product); + $this->_em->flush(); + $this->_em->clear(); + + $fetchedProduct = $this->_em->find(Product::class, $product->id); + + $this->assertInstanceOf(Unit::class, $fetchedProduct->quantity->unit); + $this->assertEquals(Unit::Gram, $fetchedProduct->quantity->unit); + } }