diff --git a/src/State.php b/src/State.php index 8d243e47..1a9afff8 100644 --- a/src/State.php +++ b/src/State.php @@ -11,6 +11,7 @@ use Thunk\Verbs\Contracts\StoresEvents; use Thunk\Verbs\Exceptions\StateNotFoundException; use Thunk\Verbs\Lifecycle\StateManager; +use Thunk\Verbs\Support\IdManager; use Thunk\Verbs\Support\Serializer; use Thunk\Verbs\Support\StateCollection; @@ -56,7 +57,7 @@ protected static function newFactory(): StateFactory public static function new() { - return static::load(snowflake()->make()); + return static::load(app(IdManager::class)->make()); } public static function loadOrFail($from): static diff --git a/tests/Feature/StateIdGenerationTest.php b/tests/Feature/StateIdGenerationTest.php new file mode 100644 index 00000000..1ec8817d --- /dev/null +++ b/tests/Feature/StateIdGenerationTest.php @@ -0,0 +1,30 @@ +toBeInstanceOf(StateIdGenerationTestState::class) + ->toHaveProperty('id') + ->and($check((string) $state->id))->toBeTrue(); +})->with([ + 'ulid' => ['ulid', [Str::class, 'isUlid']], + 'uuid' => ['uuid', [Str::class, 'isUuid']], + 'snowflake' => ['snowflake', 'validate_snowflake'], +]); + +function validate_snowflake($value): bool +{ + return preg_match('/^[1-9][0-9]{17}$/', $value); +} + +class StateIdGenerationTestState extends State {}