Skip to content

Fix StateEnum.toArray() to exercise recursion path and clean up test comments#7

Merged
maniaba merged 1 commit intobug-entityfrom
copilot/fix-enum-toarray-test
Apr 26, 2026
Merged

Fix StateEnum.toArray() to exercise recursion path and clean up test comments#7
maniaba merged 1 commit intobug-entityfrom
copilot/fix-enum-toarray-test

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 26, 2026

The original StateEnum::toArray() returned scalar strings, so the test never exercised the actual recursion path reported in the issue — where normalizeValue() calling toArray() on an enum yields more enum objects (which also have toArray()), risking infinite recursion.

Changes

  • tests/_support/Enum/StateEnum.php: Changed toArray() to return self::cases() (array of UnitEnum objects) instead of scalar strings via array_column. This ensures the test genuinely covers the recursive scenario.
  • tests/system/Entity/EntityTest.php: Removed verbose inline comments from testInjectRawDataWithEnumThatHasToArrayMethod(); replaced with a @see docblock pointing to the issue.
// Before — returns scalars, doesn't test recursion
public function toArray(): array
{
    return array_column(self::cases(), 'value');
}

// After — returns UnitEnum objects, testing that normalizeValue()
// takes the UnitEnum branch instead of calling toArray() recursively
public function toArray(): array
{
    return self::cases();
}

@maniaba maniaba marked this pull request as ready for review April 26, 2026 14:36
@maniaba maniaba merged commit 3045308 into bug-entity Apr 26, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants