mirror of
https://github.com/archtechx/enums.git
synced 2025-12-12 14:14:05 +00:00
* Extend functionality to work with pure enums * Code review changes Altered `::values()` to act like `::names()` for backed enums, code style fixes, general cleanups
34 lines
999 B
PHP
34 lines
999 B
PHP
<?php
|
|
|
|
use ArchTech\Enums\Exceptions\UndefinedCaseError;
|
|
|
|
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 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('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);
|