fix: Entity::normalizeValue() must handle UnitEnum before toArray()#5
Merged
Conversation
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>
Copilot created this pull request from a session on behalf of
maniaba
April 24, 2026 14:33
View session
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
normalizeValue()insystem/Entity/Entity.php— moveUnitEnumcheck beforeJsonSerializableandtoArraychecksStateEnumtest support class (backed enum withtoArray()) intests/_support/Enum/toRawArray()assertion (returns raw enum object, not backing value) and keep thehasChanged()assertion as the real regression check