-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3ef4ea
commit 43c156a
Showing
16 changed files
with
156 additions
and
61 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
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 was deleted.
Oops, something went wrong.
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TinyBlocks\Country\Internal; | ||
|
||
use BackedEnum; | ||
use TinyBlocks\Country\Internal\Exceptions\AlphaCodeNotFound; | ||
|
||
trait AlphaCodeMapper | ||
{ | ||
public function getBy(string $name, array $alphaCodes): BackedEnum | ||
{ | ||
foreach ($alphaCodes as $alphaCode) { | ||
if ($alphaCode->name === $name) { | ||
return $alphaCode; | ||
} | ||
} | ||
|
||
throw new AlphaCodeNotFound(name: $name); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TinyBlocks\Country\Internal\Exceptions; | ||
|
||
use RuntimeException; | ||
|
||
final class AlphaCodeNotFound extends RuntimeException | ||
{ | ||
public function __construct(string $name) | ||
{ | ||
$template = 'Alpha code with name <%s> not found.'; | ||
parent::__construct(message: sprintf($template, $name)); | ||
} | ||
} |
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
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TinyBlocks\Country\Internal; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use TinyBlocks\Country\Internal\Exceptions\AlphaCodeNotFound; | ||
use TinyBlocks\Country\Models\AlphaCodeXpto; | ||
|
||
final class AlphaCodeMapperTest extends TestCase | ||
{ | ||
public function testExceptionWhenAlphaCodeNotFound(): void | ||
{ | ||
/** @Given an AlphaCode enum case */ | ||
$alphaCode = AlphaCodeXpto::SWITZERLAND; | ||
|
||
/** @Then expect an AlphaCodeNotFound exception */ | ||
$this->expectException(AlphaCodeNotFound::class); | ||
$this->expectExceptionMessage('Alpha code with name <XXX> not found.'); | ||
|
||
/** @When calling getBy with an invalid code */ | ||
$alphaCode->getBy(name: 'XXX', alphaCodes: $alphaCode::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