98 lines
2.2 KiB
PHP
98 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Enums;
|
|
|
|
use Domain\Enums\Country;
|
|
use Domain\Exceptions\UnknownCountryIsoCodeException;
|
|
|
|
describe('CountryEnum', function () {
|
|
it('returns iso code for France', function () {
|
|
// GIVEN
|
|
$country = Country::france;
|
|
|
|
// WHEN
|
|
$iso = $country->iso();
|
|
|
|
// THEN
|
|
expect($iso)->toBe('FR');
|
|
});
|
|
|
|
it('throws exception if iso code is missing', function () {
|
|
// GIVEN
|
|
$country = Country::afghanistan;
|
|
|
|
// WHEN
|
|
$action = fn () => $country->iso();
|
|
|
|
// THEN
|
|
expect($action)->toThrow(UnknownCountryIsoCodeException::class);
|
|
});
|
|
|
|
it('returns iso num for France', function () {
|
|
// GIVEN
|
|
$country = Country::france;
|
|
|
|
// WHEN
|
|
$isoNum = $country->isoNum();
|
|
|
|
// THEN
|
|
expect($isoNum)->toBe(250);
|
|
});
|
|
|
|
it('throws exception if iso num is missing', function () {
|
|
// GIVEN
|
|
$country = Country::afghanistan;
|
|
|
|
// WHEN
|
|
$action = fn () => $country->isoNum();
|
|
|
|
// THEN
|
|
expect($action)->toThrow(UnknownCountryIsoCodeException::class);
|
|
});
|
|
|
|
it('returns null if iso code is missing via isoCode method', function () {
|
|
// GIVEN
|
|
$country = Country::afghanistan;
|
|
|
|
// WHEN
|
|
$isoCode = $country->isoCode();
|
|
|
|
// THEN
|
|
expect($isoCode)->toBeNull();
|
|
});
|
|
|
|
it('can be created from iso code', function () {
|
|
// GIVEN
|
|
$iso = 'FR';
|
|
|
|
// WHEN
|
|
$country = Country::fromIsoCode($iso);
|
|
|
|
// THEN
|
|
expect($country)->toBe(Country::france);
|
|
});
|
|
|
|
it('throws exception if created from invalid iso code', function () {
|
|
// GIVEN
|
|
$iso = 'ZZ';
|
|
|
|
// WHEN
|
|
$action = fn () => Country::fromIsoCode($iso);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(UnknownCountryIsoCodeException::class);
|
|
});
|
|
|
|
it('can list all iso codes', function () {
|
|
// GIVEN
|
|
$dummy = true;
|
|
|
|
// WHEN
|
|
$isoCodes = Country::toIsoCodes();
|
|
|
|
// THEN
|
|
expect($isoCodes)->toBeArray()->toHaveKey('france', 'FR');
|
|
});
|
|
});
|