Skip to content

Commit

Permalink
Fix random()
Browse files Browse the repository at this point in the history
  • Loading branch information
xHeaven committed Dec 25, 2024
1 parent 6f4e6d2 commit d76e036
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/EnumConcern.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static function getLabel(UnitEnum $case): string
/**
* Selects and returns a random enum case.
*/
public static function random(int $count = 1): Collection
public static function random(?int $count = null): Collection|static
{
return self::toCollection()->random($count);
}
Expand Down
8 changes: 8 additions & 0 deletions tests/FunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ function testEnumMethods($enumClass, $expectedValues, $expectedNames, $expectedA
->toBeIn($enumClass::cases());
});

it("gets a random enum case for {$enumClass} with count", function () use ($enumClass) {
$test = $enumClass::random(2);

expect($test)
->toBeInstanceOf(Collection::class)
->toHaveCount(2);
});

it("checks if a value exists in the enum for {$enumClass}", function () use ($enumClass, $expectedValues) {
$exists = $enumClass::hasValue($expectedValues[0]);
$notExists = $enumClass::hasValue('nonexistent');
Expand Down

0 comments on commit d76e036

Please sign in to comment.