Skip to content

Commit

Permalink
feat: update localize group
Browse files Browse the repository at this point in the history
  • Loading branch information
jiannei committed Oct 13, 2023
1 parent 5d20cdd commit d91897d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/Support/Traits/EnumEnhance.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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'];
Expand Down
8 changes: 4 additions & 4 deletions tests/Feature/EnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@
->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' => '订阅用户'],
]);
});

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 => '订阅用户',
]);
});
Expand Down

0 comments on commit d91897d

Please sign in to comment.