Skip to content

Commit

Permalink
add names() and values() methods, resolve #1
Browse files Browse the repository at this point in the history
  • Loading branch information
stancl committed Feb 20, 2022
1 parent e01edd1 commit b50d001
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/Names.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace ArchTech\Enums;

trait Names
{
/** Get an array of case names. */
public static function names(): array
{
return array_map(function ($case) {
return $case->name;
}, static::cases());
}
}
14 changes: 14 additions & 0 deletions src/Values.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace ArchTech\Enums;

trait Values
{
/** Get an array of case values. */
public static function values(): array
{
return array_map(function ($case) {
return $case->value;
}, static::cases());
}
}
4 changes: 3 additions & 1 deletion tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
*/

use ArchTech\Enums\InvokableCases;
use ArchTech\Enums\Names;
use ArchTech\Enums\Options;
use ArchTech\Enums\Values;

uses(ArchTech\Enums\Tests\TestCase::class)->in('Pest');

Expand Down Expand Up @@ -49,7 +51,7 @@ function something()

enum Status: int
{
use InvokableCases, Options;
use InvokableCases, Options, Names, Values;

case PENDING = 0;
case DONE = 1;
Expand Down
5 changes: 5 additions & 0 deletions tests/Pest/NamesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

it('can return an array of case names')
->expect(Status::names())
->toBe(['PENDING', 'DONE']);
5 changes: 5 additions & 0 deletions tests/Pest/ValuesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

it('can return an array of case values')
->expect(Status::values())
->toBe([0, 1]);

0 comments on commit b50d001

Please sign in to comment.