Skip to content

Commit 3045308

Browse files
Copilotmaniaba
andauthored
fix: update StateEnum.toArray and clean up test comments per review feedback (#7)
Agent-Logs-Url: https://github.com/maniaba/CodeIgniter4/sessions/81c8ece0-932b-44e0-9757-d80c5cb2fc6a Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: maniaba <[email protected]>
1 parent 76a4c33 commit 3045308

2 files changed

Lines changed: 4 additions & 13 deletions

File tree

tests/_support/Enum/StateEnum.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,13 @@
1313

1414
namespace 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-
*/
2016
enum 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
}

tests/system/Entity/EntityTest.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)