From adff7ecd85dbdbe15a2aef25ae2ae437844dee7d Mon Sep 17 00:00:00 2001 From: henzeb Date: Thu, 3 Oct 2024 15:33:21 +0200 Subject: [PATCH] fixes #6 --- src/Helpers/EnumState.php | 1 + tests/Fixtures/BackedEnums/State/PostStatus.php | 15 +++++++++++++++ tests/Unit/Concerns/StateTest.php | 6 ++++++ .../Concerns/CastsStatefulEnumerationsTest.php | 1 - 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/Fixtures/BackedEnums/State/PostStatus.php diff --git a/src/Helpers/EnumState.php b/src/Helpers/EnumState.php index 5bbe49c..5e6fcf9 100644 --- a/src/Helpers/EnumState.php +++ b/src/Helpers/EnumState.php @@ -50,6 +50,7 @@ private static function getTransitions(UnitEnum $currentTransition): array ); $transitions = $transitions[$currentTransition->name] + ?? $transitions[strtolower($currentTransition->name)] ?? $transitions[EnumValue::value($currentTransition)] ?? []; diff --git a/tests/Fixtures/BackedEnums/State/PostStatus.php b/tests/Fixtures/BackedEnums/State/PostStatus.php new file mode 100644 index 0000000..1133abe --- /dev/null +++ b/tests/Fixtures/BackedEnums/State/PostStatus.php @@ -0,0 +1,15 @@ +toMove(); } + + public function testStatesWithBackedEnum(): void + { + $this->assertEquals(PostStatus::DRAFT->to(PostStatus::READY), PostStatus::READY); + } } diff --git a/tests/Unit/Laravel/Concerns/CastsStatefulEnumerationsTest.php b/tests/Unit/Laravel/Concerns/CastsStatefulEnumerationsTest.php index c2603d3..e105a90 100644 --- a/tests/Unit/Laravel/Concerns/CastsStatefulEnumerationsTest.php +++ b/tests/Unit/Laravel/Concerns/CastsStatefulEnumerationsTest.php @@ -138,7 +138,6 @@ public function testShouldJustCastWhenEnumIsNotStatefulValue() public function testShouldAllowTransition() { - $this->expectException(IllegalEnumTransitionException::class); $model = new CastsStatefulEnumsModel(); $model->stringBackedEnum = StringBackedGetEnum::TEST;