-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from MarkBaker/Add-CasesIndexedByName-Trait
Add cases indexed by name trait
- Loading branch information
Showing
7 changed files
with
207 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace EnumHelper; | ||
|
||
trait CasesIndexedByName | ||
{ | ||
/** | ||
* @return array<string, self> | ||
*/ | ||
public static function casesIndexedByName() | ||
{ | ||
return array_combine( | ||
array_map( | ||
fn(self $case) => $case->name, | ||
self::cases() | ||
), | ||
self::cases() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace EnumHelper\Tests; | ||
|
||
use EnumHelper\TestData\EnumSuit; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class CasesIndexedByNameTest extends TestCase | ||
{ | ||
public function testCasesIndexedByName() | ||
{ | ||
$cases = EnumSuit::casesIndexedByName(); | ||
|
||
foreach ($cases as $caseName => $case) { | ||
self::assertSame($case->name, $caseName); | ||
} | ||
} | ||
} |