1
0
Fork 0
mirror of https://github.com/archtechx/enums.git synced 2025-12-12 08:04:04 +00:00
enums/tests/Pest/InvokableCasesTest.php
Samuel Levy 0c87357a6e
Extend functionality to work with pure enums (#6)
* Extend functionality to work with pure enums

* Code review changes

Altered `::values()` to act like `::names()` for backed enums, code style fixes, general cleanups
2022-03-23 21:42:35 +01:00

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);