diff --git a/src/Support/Traits/EnumEnhance.php b/src/Support/Traits/EnumEnhance.php index 67ff114..c87b123 100644 --- a/src/Support/Traits/EnumEnhance.php +++ b/src/Support/Traits/EnumEnhance.php @@ -26,7 +26,7 @@ public function value(): int|string return $this->value; } - public function description(string $localizationGroup = '*'): string + public function description(string $localizationGroup = 'enums'): string { $key = "$localizationGroup.".static::class.'.'.$this->value; @@ -95,7 +95,7 @@ public static function guess(int|string $key): static }; } - public static function toArray(string $localizationGroup = '*'): array + public static function toArray(string $localizationGroup = 'enums'): array { return array_map(fn (\BackedEnum $item) => [ 'name' => $item->name, @@ -104,7 +104,7 @@ public static function toArray(string $localizationGroup = '*'): array ], static::cases()); } - public static function toSelectArray(string $localizationGroup = '*'): array + public static function toSelectArray(string $localizationGroup = 'enums'): array { return array_reduce(static::toArray($localizationGroup), function ($carry, $item) { $carry[$item['value']] = $item['description']; diff --git a/tests/Feature/EnumTest.php b/tests/Feature/EnumTest.php index beaceff..9a5ff86 100644 --- a/tests/Feature/EnumTest.php +++ b/tests/Feature/EnumTest.php @@ -19,7 +19,7 @@ ->and(UserType::values())->toBeArray()->toMatchArray([0, 1, 2]) ->and(UserType::toArray())->toBeArray()->toMatchArray([ ['name' => 'ADMINISTRATOR', 'value' => 0, 'description' => '管理员'], - ['name' => 'MODERATOR', 'value' => 1, 'description' => '监督员'], + ['name' => 'MODERATOR', 'value' => 1, 'description' => '主持人'], ['name' => 'SUBSCRIBER', 'value' => 2, 'description' => '订阅用户'], ]); }); @@ -27,15 +27,15 @@ test('to select array', function () { expect(UserType::toSelectArray())->toMatchArray([ 0 => '管理员', - 1 => '监督员', + 1 => '主持人', 2 => '订阅用户', ]); }); test('specify localization group', function () { - expect(UserType::toSelectArray('enums'))->toMatchArray([ + expect(UserType::toSelectArray('*'))->toMatchArray([ 0 => '管理员', - 1 => '主持人', + 1 => '监督员', 2 => '订阅用户', ]); });