Skip to content

Commit

Permalink
Merge pull request #351 from yunicot/bugfix-enum-failed-reflection
Browse files Browse the repository at this point in the history
add proxy methods to EnumReflectionProperty
  • Loading branch information
malarzm authored Mar 12, 2024
2 parents b6fd1f1 + e712777 commit 477da35
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Persistence/Reflection/EnumReflectionProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,24 @@ private function toEnum($value)

return $this->enumType::from($value);
}

/**
* {@inheritDoc}
*
* @psalm-external-mutation-free
*/
public function getModifiers(): int
{
return $this->originalReflectionProperty->getModifiers();
}

/**
* {@inheritDoc}
*
* @psalm-external-mutation-free
*/
public function getDocComment(): string|false
{
return $this->originalReflectionProperty->getDocComment();
}
}
13 changes: 13 additions & 0 deletions tests_php81/Persistence/Reflection/EnumReflectionPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ public function testSetEnumArray(): void

self::assertSame([Suit::Hearts, Suit::Diamonds], $object->suits);
}

public function testGetModifiers(): void
{
$reflProperty = new EnumReflectionProperty(new ReflectionProperty(TypedEnumClass::class, 'suit'), Suit::class);
self::assertSame(ReflectionProperty::IS_PUBLIC, $reflProperty->getModifiers());
}

public function testGetDocComment(): void
{
$reflProperty = new EnumReflectionProperty(new ReflectionProperty(TypedEnumClass::class, 'suit'), Suit::class);
self::assertStringContainsString('@MyDoc', $reflProperty->getDocComment());
}
}

#[Attribute(Attribute::TARGET_PROPERTY)]
Expand All @@ -122,6 +134,7 @@ class MyAttribute

class TypedEnumClass
{
/** @MyDoc */
#[MyAttribute]
public ?Suit $suit = null;

Expand Down

0 comments on commit 477da35

Please sign in to comment.