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')); }