From 2c693d90459d49233514db2e784e0d72a4b09f7a Mon Sep 17 00:00:00 2001 From: K Muller Date: Mon, 28 Sep 2026 14:57:31 +0200 Subject: [PATCH] fix: :bug: country in shared --- .../ValueObjects/CountryAuthorizedTest.php | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/Unit/Domain/Models/ValueObjects/CountryAuthorizedTest.php diff --git a/tests/Unit/Domain/Models/ValueObjects/CountryAuthorizedTest.php b/tests/Unit/Domain/Models/ValueObjects/CountryAuthorizedTest.php new file mode 100644 index 0000000..4019b00 --- /dev/null +++ b/tests/Unit/Domain/Models/ValueObjects/CountryAuthorizedTest.php @@ -0,0 +1,65 @@ +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'); + }); +});