65 lines
1.9 KiB
PHP
65 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects;
|
|
|
|
use Shared\Enums\Country;
|
|
use Domain\Models\ValueObjects\CountryAuthorized;
|
|
|
|
covers(CountryAuthorized::class);
|
|
|
|
describe('country authorized', function (): void {
|
|
it('creates a valid authorized country', function (string $case): void {
|
|
// GIVEN
|
|
$country = Country::from($case);
|
|
|
|
// WHEN
|
|
$authorized = new CountryAuthorized($country);
|
|
|
|
// THEN
|
|
expect($authorized)->toBeInstanceOf(CountryAuthorized::class)
|
|
->and($authorized->country)->toBe($country);
|
|
})->with([
|
|
'france' => 'france',
|
|
'belgium' => 'belgium',
|
|
'luxembourg' => 'luxembourg',
|
|
]);
|
|
|
|
it('rejects a country that is not authorized', function (): void {
|
|
// WHEN
|
|
$action = fn (): CountryAuthorized => new CountryAuthorized(Country::GERMANY);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'Country "GERMANY" is not authorized.');
|
|
});
|
|
|
|
it('lists the authorized countries', function (): void {
|
|
// THEN
|
|
expect(CountryAuthorized::authorizedCountries())->toBe([
|
|
Country::FRANCE,
|
|
Country::BELGIUM,
|
|
Country::LUXEMBOURG,
|
|
]);
|
|
});
|
|
|
|
it('implements equals correctly', function (): void {
|
|
// GIVEN
|
|
$france1 = new CountryAuthorized(Country::FRANCE);
|
|
$france2 = new CountryAuthorized(Country::FRANCE);
|
|
$belgium = new CountryAuthorized(Country::BELGIUM);
|
|
|
|
// THEN
|
|
expect($france1->equals($france2))->toBeTrue()
|
|
->and($france1->equals($belgium))->toBeFalse()
|
|
->and($france1->equals(null))->toBeFalse();
|
|
});
|
|
|
|
it('converts to string as the country backing value', function (): void {
|
|
// GIVEN
|
|
$authorized = new CountryAuthorized(Country::FRANCE);
|
|
|
|
// THEN
|
|
expect((string) $authorized)->toBe('france');
|
|
});
|
|
});
|