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 d03672d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Helpers/EnumState.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static function getTransitions(UnitEnum $currentTransition): array
EnumState::transitions($currentTransition::class, $currentTransition::class::transitions())
);

$transitions = $transitions[$currentTransition->name]
$transitions = $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);
}
}

0 comments on commit d03672d

Please sign in to comment.