From 6a709ff996bee90b45d31c09a3685b833118259f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 26 Apr 2026 14:34:21 +0000 Subject: [PATCH] fix: update StateEnum.toArray and clean up test comments per review feedback Agent-Logs-Url: https://github.com/maniaba/CodeIgniter4/sessions/81c8ece0-932b-44e0-9757-d80c5cb2fc6a Co-authored-by: maniaba <61078470+maniaba@users.noreply.github.com> --- tests/_support/Enum/StateEnum.php | 6 +----- tests/system/Entity/EntityTest.php | 11 +++-------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/tests/_support/Enum/StateEnum.php b/tests/_support/Enum/StateEnum.php index 84d6a1713aae..5b151e167862 100644 --- a/tests/_support/Enum/StateEnum.php +++ b/tests/_support/Enum/StateEnum.php @@ -13,10 +13,6 @@ namespace Tests\Support\Enum; -/** - * An enum that also defines toArray(), used to test that UnitEnum handling - * takes precedence over toArray() in Entity::normalizeValue(). - */ enum StateEnum: string { case DRAFT = 'draft'; @@ -24,6 +20,6 @@ enum StateEnum: string public function toArray(): array { - return array_column(self::cases(), 'value'); + return self::cases(); } } diff --git a/tests/system/Entity/EntityTest.php b/tests/system/Entity/EntityTest.php index 59445f6c294d..804d33b0b9d7 100644 --- a/tests/system/Entity/EntityTest.php +++ b/tests/system/Entity/EntityTest.php @@ -1046,21 +1046,16 @@ public function testCastEnumSetWithUnitEnumObject(): void $this->assertSame(ColorEnum::RED, $entity->color); } + /** + * @see https://github.com/codeigniter4/CodeIgniter4/issues/10136 + */ public function testInjectRawDataWithEnumThatHasToArrayMethod(): void { - // Regression test for https://github.com/codeigniter4/CodeIgniter4/issues/10136 - // Enums implementing toArray() must still be handled by the UnitEnum branch in - // normalizeValue(), so hasChanged() does not incorrectly report a change after - // injectRawData() stores the same enum value. $entity = new class () extends Entity {}; $entity->injectRawData(['state' => StateEnum::DRAFT]); - // toRawArray() returns raw attributes, so the enum object is returned as-is. $this->assertSame(StateEnum::DRAFT, $entity->toRawArray()['state']); - - // The key assertion: normalizeValue() must treat the enum as a UnitEnum - // (not call toArray() on it), so the original and current normalized forms match. $this->assertFalse($entity->hasChanged('state')); }