1
0
Fork 0
mirror of https://github.com/archtechx/enums.git synced 2025-12-15 17:14:03 +00:00

from(int|string), tryFrom(int|string)

This commit is contained in:
Samuel Štancl 2025-06-07 01:03:01 +02:00
parent bdd8de68ff
commit 859fb9a03c
13 changed files with 26 additions and 2 deletions

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
test('the is method checks for equality', function () {
expect(Status::PENDING->is(Status::PENDING))->toBeTrue();
expect(Status::PENDING->is(Status::DONE))->toBeFalse();

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
it('does not override the default BackedEnum from method')
->expect(Status::from(0))
->toBe(Status::PENDING);

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
use ArchTech\Enums\Exceptions\UndefinedCaseError;
it('can be used as a static method with backed enums', function () {

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
test('pure enums can have metadata on cases', function () {
expect(Role::ADMIN->color())->toBe('indigo');
expect(Role::GUEST->color())->toBe('gray');

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
it('can return an array of case names from backed enums')
->expect(Status::names())
->toBe(['PENDING', 'DONE']);

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
it('can return an associative array of options from a backed enum')
->expect(Status::options())->toBe([
'PENDING' => 0,

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
use ArchTech\Enums\Meta\Meta;
use ArchTech\Enums\Meta\MetaProperty;
use ArchTech\Enums\Metadata;

View file

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
it('can return an array of case values from a backed enum')
->expect(Status::values())
->toBe([0, 1]);