File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313
1414namespace Tests \Support \Enum ;
1515
16- /**
17- * An enum that also defines toArray(), used to test that UnitEnum handling
18- * takes precedence over toArray() in Entity::normalizeValue().
19- */
2016enum StateEnum: string
2117{
2218 case DRAFT = 'draft ' ;
2319 case PUBLISHED = 'published ' ;
2420
2521 public function toArray (): array
2622 {
27- return array_column ( self ::cases (), ' value ' );
23+ return self ::cases ();
2824 }
2925}
Original file line number Diff line number Diff line change @@ -1046,21 +1046,16 @@ public function testCastEnumSetWithUnitEnumObject(): void
10461046 $ this ->assertSame (ColorEnum::RED , $ entity ->color );
10471047 }
10481048
1049+ /**
1050+ * @see https://github.com/codeigniter4/CodeIgniter4/issues/10136
1051+ */
10491052 public function testInjectRawDataWithEnumThatHasToArrayMethod (): void
10501053 {
1051- // Regression test for https://github.com/codeigniter4/CodeIgniter4/issues/10136
1052- // Enums implementing toArray() must still be handled by the UnitEnum branch in
1053- // normalizeValue(), so hasChanged() does not incorrectly report a change after
1054- // injectRawData() stores the same enum value.
10551054 $ entity = new class () extends Entity {};
10561055
10571056 $ entity ->injectRawData (['state ' => StateEnum::DRAFT ]);
10581057
1059- // toRawArray() returns raw attributes, so the enum object is returned as-is.
10601058 $ this ->assertSame (StateEnum::DRAFT , $ entity ->toRawArray ()['state ' ]);
1061-
1062- // The key assertion: normalizeValue() must treat the enum as a UnitEnum
1063- // (not call toArray() on it), so the original and current normalized forms match.
10641059 $ this ->assertFalse ($ entity ->hasChanged ('state ' ));
10651060 }
10661061
You can’t perform that action at this time.
0 commit comments