1
0
Fork 0
mirror of https://github.com/archtechx/enums.git synced 2025-12-12 21:54:04 +00:00

Add stringOptions() method to the Options trait (resolve #12)

This commit is contained in:
Samuel Štancl 2024-01-12 23:11:09 +01:00
parent f8438b0313
commit 6684067b9e
2 changed files with 47 additions and 1 deletions

View file

@ -11,3 +11,19 @@ it('can return an indexed array of options from a pure enum')
0 => 'ADMIN',
1 => 'GUEST',
]);
it('can return a string of options from a backed enum')
->expect(Status::stringOptions(fn ($name, $value) => "$name => $value", ', '))
->toBe("PENDING => 0, DONE => 1");
it('can return a string of options from a pure enum')
->expect(Role::stringOptions(fn ($name, $value) => "$name => $value", ', '))
->toBe("ADMIN => ADMIN, GUEST => GUEST");
it('returns default HTML options from backed enums')
->expect(Status::stringOptions())
->toBe('<option value="0">Pending</option>\n<option value="1">Done</option>');
it('returns default HTML options from pure enums')
->expect(Role::stringOptions())
->toBe('<option value="ADMIN">Admin</option>\n<option value="GUEST">Guest</option>');