Skip to content

Commit

Permalink
fixes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
henzeb committed Oct 3, 2024
1 parent cbf1230 commit adff7ec
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Helpers/EnumState.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private static function getTransitions(UnitEnum $currentTransition): array
);

$transitions = $transitions[$currentTransition->name]
?? $transitions[strtolower($currentTransition->name)]
?? $transitions[EnumValue::value($currentTransition)]
?? [];

Expand Down
15 changes: 15 additions & 0 deletions tests/Fixtures/BackedEnums/State/PostStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Henzeb\Enumhancer\Tests\Fixtures\BackedEnums\State;

use Henzeb\Enumhancer\Concerns\State;

enum PostStatus: string
{
use State;

case DRAFT = 'DRAFT';
case READY = 'READY';
case PUBLISHED = 'PUBLISHED';
case ARCHIVED = 'ARCHIVED';
}
6 changes: 6 additions & 0 deletions tests/Unit/Concerns/StateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Henzeb\Enumhancer\Contracts\TransitionHook;
use Henzeb\Enumhancer\Exceptions\IllegalEnumTransitionException;
use Henzeb\Enumhancer\Tests\Fixtures\BackedEnums\State\PostStatus;
use Henzeb\Enumhancer\Tests\Fixtures\UnitEnums\State\StateElevatorComplexEnum;
use Henzeb\Enumhancer\Tests\Fixtures\UnitEnums\State\StateElevatorDisableTransitionEnum;
use Henzeb\Enumhancer\Tests\Fixtures\UnitEnums\State\StateElevatorEnum;
Expand Down Expand Up @@ -313,4 +314,9 @@ public function testMagicCallsWithHooks(): void

StateElevatorEnum::Open->toMove();
}

public function testStatesWithBackedEnum(): void
{
$this->assertEquals(PostStatus::DRAFT->to(PostStatus::READY), PostStatus::READY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ public function testShouldJustCastWhenEnumIsNotStatefulValue()

public function testShouldAllowTransition()
{
$this->expectException(IllegalEnumTransitionException::class);
$model = new CastsStatefulEnumsModel();

$model->stringBackedEnum = StringBackedGetEnum::TEST;
Expand Down

0 comments on commit adff7ec

Please sign in to comment.