Skip to content

Commit

Permalink
Merge pull request #3 from faustbrian/keys-and-values
Browse files Browse the repository at this point in the history
add getKeys and getValues methods
  • Loading branch information
brendt committed Feb 11, 2019
2 parents 32ae8cc + 17d25aa commit b47dfe4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Enum.php
Expand Up @@ -100,6 +100,16 @@ public static function toArray(): array
return self::resolve();
}

public static function getKeys(): array
{
return array_keys(self::resolve());
}

public static function getValues(): array
{
return array_values(self::resolve());
}

protected static function resolve(): array
{
$class = static::class;
Expand Down
12 changes: 12 additions & 0 deletions tests/EnumTest.php
Expand Up @@ -95,4 +95,16 @@ public function json_encode_test()

$this->assertEquals('"bar"', $json);
}

/** @test */
public function it_can_represent_its_keys_as_an_array()
{
$this->assertEquals(['foo', 'bar'], MyEnum::getKeys());
}

/** @test */
public function it_can_represent_its_values_as_an_array()
{
$this->assertEquals(['foovalue', 'bar'], MyEnum::getValues());
}
}

0 comments on commit b47dfe4

Please sign in to comment.