fix: 🐛 country in shared
This commit is contained in:
parent
69faddcd08
commit
2c693d9045
1 changed files with 65 additions and 0 deletions
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Domain\Models\ValueObjects;
|
||||
|
||||
use Domain\Models\ValueObjects\CountryAuthorized;
|
||||
use Shared\Enums\Country;
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue