Skip to content

fix: Entity::normalizeValue() must handle UnitEnum before toArray()#5

Merged
maniaba merged 2 commits into
bug-entityfrom
copilot/bug-entity
Apr 24, 2026
Merged

fix: Entity::normalizeValue() must handle UnitEnum before toArray()#5
maniaba merged 2 commits into
bug-entityfrom
copilot/bug-entity

Conversation

Copilot AI commented Apr 24, 2026

Copy link
Copy Markdown
  • Fix normalizeValue() in system/Entity/Entity.php — move UnitEnum check before JsonSerializable and toArray checks
  • Add StateEnum test support class (backed enum with toArray()) in tests/_support/Enum/
  • Fix regression test — correct toRawArray() assertion (returns raw enum object, not backing value) and keep the hasChanged() assertion as the real regression check

Moves the `UnitEnum` instanceof check before `JsonSerializable` and
`method_exists($data, 'toArray')` in Entity::normalizeValue(), so that
enums implementing toArray() are always normalized as enums rather than
as generic objects.

Fixes codeigniter4#10136

Agent-Logs-Url: https://github.com/maniaba/CodeIgniter4/sessions/d5c8c660-329b-4872-8633-dd918674e4ac

Co-authored-by: maniaba <61078470+maniaba@users.noreply.github.com>
toRawArray() returns raw $this->attributes, so an injected enum object
stays as an enum object — not the backing string value. The real
regression is that hasChanged() must return false (normalizeValue()
handles UnitEnum before toArray()).

Fixes the failing test from the previous commit.

Agent-Logs-Url: https://github.com/maniaba/CodeIgniter4/sessions/d86b9a68-aee9-4178-a8b8-cf1bac285359

Co-authored-by: maniaba <61078470+maniaba@users.noreply.github.com>
@maniaba maniaba marked this pull request as ready for review April 24, 2026 14:42
@maniaba maniaba changed the base branch from develop to bug-entity April 24, 2026 14:42
@maniaba maniaba merged commit 94a05ff into bug-entity Apr 24, 2026
28 checks passed
@maniaba maniaba deleted the copilot/bug-entity branch April 24, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants