-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert PhoneNumberType & PhoneNumberFormat to enums
- Loading branch information
Showing
7 changed files
with
81 additions
and
98 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 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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Brick\PhoneNumber\Tests; | ||
|
||
use BackedEnum; | ||
use Brick\PhoneNumber\PhoneNumberFormat; | ||
use Brick\PhoneNumber\PhoneNumberType; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Tests that enums are up-to-date with libphonenumber constants. | ||
*/ | ||
class EnumTest extends TestCase | ||
{ | ||
/** | ||
* @param class-string $classExpected The name or the reference libphonenumber class. | ||
* @param class-string<BackedEnum> $enumClassActual The name of the enum class to test against the reference class. | ||
*/ | ||
private static function assertEnumEqualsConstants(string $classExpected, string $enumClassActual) : void | ||
{ | ||
$expected = (new \ReflectionClass($classExpected))->getConstants(); | ||
|
||
$actual = []; | ||
|
||
foreach ($enumClassActual::cases() as $enum) { | ||
$actual[$enum->name] = $enum->value; | ||
} | ||
|
||
self::assertSame($expected, $actual); | ||
} | ||
|
||
public function testPhoneNumberFormats() : void | ||
{ | ||
self::assertEnumEqualsConstants(\libphonenumber\PhoneNumberFormat::class, PhoneNumberFormat::class); | ||
} | ||
|
||
public function testPhoneNumberTypes() : void | ||
{ | ||
self::assertEnumEqualsConstants(\libphonenumber\PhoneNumberType::class, PhoneNumberType::class); | ||
} | ||
} |
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