mirror of
https://github.com/archtechx/enums.git
synced 2025-12-12 21:04:03 +00:00
Extend functionality to work with pure enums
This commit is contained in:
parent
20fa78c2b1
commit
c2f0e7faf7
8 changed files with 99 additions and 15 deletions
|
|
@ -2,18 +2,33 @@
|
|||
|
||||
use ArchTech\Enums\Exceptions\UndefinedCaseError;
|
||||
|
||||
it('can be used as a static method', function () {
|
||||
it('can be used as a static method with backed enums', function () {
|
||||
expect(Status::PENDING())->toBe(0);
|
||||
expect(Status::DONE())->toBe(1);
|
||||
});
|
||||
|
||||
it('can be invoked as an instance', function () {
|
||||
it('can be used as a static method with pure enums', function () {
|
||||
expect(Role::ADMIN())->toBe('ADMIN');
|
||||
expect(Role::GUEST())->toBe('GUEST');
|
||||
});
|
||||
|
||||
it('can be invoked as an instance as a backed enum', function () {
|
||||
$status = Status::PENDING;
|
||||
|
||||
expect($status())->toBe(0);
|
||||
expect($status())->toBe($status->value);
|
||||
});
|
||||
|
||||
it('throws an error when a nonexistent case is being used', function () {
|
||||
it('can be invoked as an instance as a pure enum', function () {
|
||||
$role = Role::ADMIN;
|
||||
|
||||
expect($role())->toBe('ADMIN');
|
||||
});
|
||||
|
||||
it('throws an error when a nonexistent case is being used for backed enums', function () {
|
||||
Status::INVALID();
|
||||
})->expectException(UndefinedCaseError::class);
|
||||
|
||||
it('throws an error when a nonexistent case is being used for pure enums', function () {
|
||||
Role::INVALID();
|
||||
})->expectException(UndefinedCaseError::class);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
<?php
|
||||
|
||||
it('can return an array of case names')
|
||||
it('can return an array of case names from backed enums')
|
||||
->expect(Status::names())
|
||||
->toBe(['PENDING', 'DONE']);
|
||||
|
||||
it('can return an array of case names from pure enums')
|
||||
->expect(Role::names())
|
||||
->toBe(['ADMIN', 'GUEST']);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,13 @@
|
|||
<?php
|
||||
|
||||
it('can return an associative array of options')
|
||||
it('can return an associative array of options from a backed enum')
|
||||
->expect(Status::options())->toBe([
|
||||
'PENDING' => 0,
|
||||
'DONE' => 1,
|
||||
]);
|
||||
|
||||
it('can return an indexed array of options from a pure enum')
|
||||
->expect(Role::options())->toBe([
|
||||
0 => 'ADMIN',
|
||||
1 => 'GUEST',
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
<?php
|
||||
|
||||
it('can return an array of case values')
|
||||
it('can return an array of case values from a backed enum')
|
||||
->expect(Status::values())
|
||||
->toBe([0, 1]);
|
||||
|
||||
it('can returns an empty array from a pure enum')
|
||||
->expect(Role::values())
|
||||
->toBe([]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue