From 44c65cf9f68c93edd25fcddc05bb5c86043b03e5 Mon Sep 17 00:00:00 2001 From: K Muller Date: Tue, 29 Sep 2026 09:02:22 +0200 Subject: [PATCH] feat: :sparkles: country enum is on coupon, and used as a backup --- .../Find/FindCampaignRequest.php | 1 - .../Find/Output/CampaignRequestFound.php | 1 - .../Models/Entities/CampaignRequest.php | 5 ---- .../Models/ValueObjects/CountryAuthorized.php | 23 ++++++++++++------- .../RequestedCoupon/RequestedCoupon.php | 2 ++ src/Shared/Enums/Country.php | 8 +++++++ .../Find/FindCampaignRequestTest.php | 5 +--- .../List/ListCampaignsRequestTest.php | 4 ++-- .../Reject/RejectCampaignRequestTest.php | 3 +-- .../Models/Entities/CampaignRequestTest.php | 14 +---------- .../RequestedCoupon/RequestedCouponTest.php | 8 +++++-- 11 files changed, 36 insertions(+), 38 deletions(-) diff --git a/src/Application/UseCases/CampaignRequest/Find/FindCampaignRequest.php b/src/Application/UseCases/CampaignRequest/Find/FindCampaignRequest.php index 7e28121..c4737e6 100644 --- a/src/Application/UseCases/CampaignRequest/Find/FindCampaignRequest.php +++ b/src/Application/UseCases/CampaignRequest/Find/FindCampaignRequest.php @@ -45,7 +45,6 @@ final readonly class FindCampaignRequest implements UseCase return new CampaignRequestFound( brand: $brand, applicant: $campaignRequest->applicant, - country: $campaignRequest->country, campaignType: $campaignRequest->campaignType, printRules: $campaignRequest->printRules, requestedCoupon: $campaignRequest->requestedCoupon, diff --git a/src/Application/UseCases/CampaignRequest/Find/Output/CampaignRequestFound.php b/src/Application/UseCases/CampaignRequest/Find/Output/CampaignRequestFound.php index 08dafd7..13ef470 100644 --- a/src/Application/UseCases/CampaignRequest/Find/Output/CampaignRequestFound.php +++ b/src/Application/UseCases/CampaignRequest/Find/Output/CampaignRequestFound.php @@ -18,7 +18,6 @@ final readonly class CampaignRequestFound implements Output public function __construct( public Brand $brand, public Applicant $applicant, - public CountryAuthorized $country, public CampaignRequestType $campaignType, public ?PrintRules $printRules, public RequestedCoupon $requestedCoupon, diff --git a/src/Domain/Models/Entities/CampaignRequest.php b/src/Domain/Models/Entities/CampaignRequest.php index 399ac65..3a1674c 100644 --- a/src/Domain/Models/Entities/CampaignRequest.php +++ b/src/Domain/Models/Entities/CampaignRequest.php @@ -10,7 +10,6 @@ use Domain\Models\ValueObjects\Brand\BrandCode; use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestId; use Domain\Models\ValueObjects\CampaignRequest\Applicant; use Domain\Models\ValueObjects\CampaignRequest\RejectionReason; -use Domain\Models\ValueObjects\CountryAuthorized; use Domain\Models\ValueObjects\PrintRules; use Domain\Models\ValueObjects\RequestedCoupon\RequestedCoupon; use Shared\DDD\Models\AggregateRoot; @@ -26,7 +25,6 @@ final readonly class CampaignRequest implements AggregateRoot, HasTimestampIdent public CampaignRequestId $id, public BrandCode $code, public Applicant $applicant, - public CountryAuthorized $country, public CampaignRequestType $campaignType, public ?PrintRules $printRules, public RequestedCoupon $requestedCoupon, @@ -63,7 +61,6 @@ final readonly class CampaignRequest implements AggregateRoot, HasTimestampIdent CampaignRequestId $id, BrandCode $code, Applicant $applicant, - CountryAuthorized $country, CampaignRequestType $campaignType, ?PrintRules $printRules, RequestedCoupon $requestedCoupon, @@ -75,7 +72,6 @@ final readonly class CampaignRequest implements AggregateRoot, HasTimestampIdent id: $id, code: $code, applicant: $applicant, - country: $country, campaignType: $campaignType, printRules: $printRules, requestedCoupon: $requestedCoupon, @@ -95,7 +91,6 @@ final readonly class CampaignRequest implements AggregateRoot, HasTimestampIdent id: $this->id, code: $this->code, applicant: $this->applicant, - country: $this->country, campaignType: $this->campaignType, printRules: $this->printRules, requestedCoupon: $this->requestedCoupon, diff --git a/src/Domain/Models/ValueObjects/CountryAuthorized.php b/src/Domain/Models/ValueObjects/CountryAuthorized.php index 74c6515..948ab60 100644 --- a/src/Domain/Models/ValueObjects/CountryAuthorized.php +++ b/src/Domain/Models/ValueObjects/CountryAuthorized.php @@ -11,17 +11,21 @@ use Shared\Enums\Country; final readonly class CountryAuthorized implements \Stringable, Equatable { /** @var list */ - private const array AUTHORIZED = [ - Country::FRANCE, - Country::BELGIUM, - Country::LUXEMBOURG, - ]; + private static function authorized(): array + { + return [ + Country::FRANCE, + ...Country::benelux(), + ]; + } public function __construct( public Country $country, ) { - if (! in_array($this->country, self::AUTHORIZED, true)) { - throw new \DomainException(sprintf('Country "%s" is not authorized.', $this->country->name)); + if (! in_array($this->country, self::authorized(), true)) { + throw new \DomainException( + sprintf('Country "%s" is not authorized.', $this->country->name) + ); } } @@ -30,7 +34,10 @@ final readonly class CountryAuthorized implements \Stringable, Equatable */ public static function authorizedCountries(): array { - return self::AUTHORIZED; + return [ + Country::FRANCE, + ...Country::benelux(), + ]; } #[Override] diff --git a/src/Domain/Models/ValueObjects/RequestedCoupon/RequestedCoupon.php b/src/Domain/Models/ValueObjects/RequestedCoupon/RequestedCoupon.php index 616c082..99485f5 100644 --- a/src/Domain/Models/ValueObjects/RequestedCoupon/RequestedCoupon.php +++ b/src/Domain/Models/ValueObjects/RequestedCoupon/RequestedCoupon.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Domain\Models\ValueObjects\RequestedCoupon; +use Domain\Models\ValueObjects\CountryAuthorized; use Domain\Models\ValueObjects\Coupon\CouponValidity; use Domain\Models\ValueObjects\CouponName; use Domain\Models\ValueObjects\CouponPicture; @@ -27,6 +28,7 @@ final readonly class RequestedCoupon public CouponPicture $couponPicture, public GS1 $gs1, public CouponValidity $couponValidity, + public CountryAuthorized $country, ) { } } diff --git a/src/Shared/Enums/Country.php b/src/Shared/Enums/Country.php index 857447a..b910688 100644 --- a/src/Shared/Enums/Country.php +++ b/src/Shared/Enums/Country.php @@ -583,4 +583,12 @@ enum Country: string { return self::ISOCODES; } + + public static function benelux(): array + { + return [ + self::BELGIUM, + self::LUXEMBOURG + ]; + } } diff --git a/tests/Unit/Application/UseCases/CampaignRequest/Find/FindCampaignRequestTest.php b/tests/Unit/Application/UseCases/CampaignRequest/Find/FindCampaignRequestTest.php index afbf59f..e8eb36f 100644 --- a/tests/Unit/Application/UseCases/CampaignRequest/Find/FindCampaignRequestTest.php +++ b/tests/Unit/Application/UseCases/CampaignRequest/Find/FindCampaignRequestTest.php @@ -60,6 +60,7 @@ describe('find campaign request use case', function (): void { new CouponPicture(new PicturePath('coupons/product.jpg'), new PicturePath('coupons/thumbnail.jpg')), new GS1('01234567890128', BarcodeFormat::EAN13), new CouponValidity(30, new DateTime()), + new CountryAuthorized(Country::FRANCE) ); }); @@ -71,7 +72,6 @@ describe('find campaign request use case', function (): void { $id, $code, new Applicant('John', 'Doe', new Email('john.doe@example.com')), - new CountryAuthorized(Country::FRANCE), CampaignRequestType::CLUB, new PrintRules(maxPerCustomer: 3), $this->requestedCoupon, @@ -101,7 +101,6 @@ describe('find campaign request use case', function (): void { expect($result)->toBeInstanceOf(CampaignRequestFound::class) ->and($result->brand)->toBe($brand) ->and($result->applicant)->toBe($campaignRequest->applicant) - ->and($result->country)->toBe($campaignRequest->country) ->and($result->campaignType)->toBe($campaignRequest->campaignType) ->and($result->printRules)->toBe($campaignRequest->printRules) ->and($result->requestedCoupon)->toBe($campaignRequest->requestedCoupon) @@ -118,7 +117,6 @@ describe('find campaign request use case', function (): void { $id, $code, new Applicant('John', 'Doe', new Email('john.doe@example.com')), - new CountryAuthorized(Country::FRANCE), CampaignRequestType::CLUB, new PrintRules(maxPerCustomer: 3), $this->requestedCoupon, @@ -179,7 +177,6 @@ describe('find campaign request use case', function (): void { $id, $code, new Applicant('John', 'Doe', new Email('john.doe@example.com')), - new CountryAuthorized(Country::FRANCE), CampaignRequestType::CLUB, new PrintRules(maxPerCustomer: 3), $this->requestedCoupon, diff --git a/tests/Unit/Application/UseCases/CampaignRequest/List/ListCampaignsRequestTest.php b/tests/Unit/Application/UseCases/CampaignRequest/List/ListCampaignsRequestTest.php index 0fb9f32..0b0d738 100644 --- a/tests/Unit/Application/UseCases/CampaignRequest/List/ListCampaignsRequestTest.php +++ b/tests/Unit/Application/UseCases/CampaignRequest/List/ListCampaignsRequestTest.php @@ -53,6 +53,7 @@ describe('list campaigns request use case', function (): void { new CouponPicture(new PicturePath('coupons/product.jpg'), new PicturePath('coupons/thumbnail.jpg')), new GS1('01234567890128', BarcodeFormat::EAN13), new CouponValidity(30, new DateTime()), + new CountryAuthorized(Country::FRANCE) ); $this->couponB = new RequestedCoupon( @@ -66,6 +67,7 @@ describe('list campaigns request use case', function (): void { new CouponPicture(new PicturePath('coupons/product.jpg'), new PicturePath('coupons/thumbnail.jpg')), new GS1('01234567890128', BarcodeFormat::EAN13), new CouponValidity(30, new DateTime()), + new CountryAuthorized(Country::FRANCE) ); }); @@ -76,7 +78,6 @@ describe('list campaigns request use case', function (): void { CampaignRequestId::generate(), new BrandCode('AAA01'), new Applicant('John', 'Doe', new Email('john.doe@example.com')), - new CountryAuthorized(Country::FRANCE), CampaignRequestType::CLUB, new PrintRules(maxPerCustomer: 3), $this->couponA, @@ -86,7 +87,6 @@ describe('list campaigns request use case', function (): void { CampaignRequestId::generate(), new BrandCode('AAA02'), new Applicant('John', 'Doe', new Email('john.doe@example.com')), - new CountryAuthorized(Country::FRANCE), CampaignRequestType::CLUB, new PrintRules(maxPerCustomer: 3), $this->couponB, diff --git a/tests/Unit/Application/UseCases/CampaignRequest/Reject/RejectCampaignRequestTest.php b/tests/Unit/Application/UseCases/CampaignRequest/Reject/RejectCampaignRequestTest.php index d4c6703..a80d22e 100644 --- a/tests/Unit/Application/UseCases/CampaignRequest/Reject/RejectCampaignRequestTest.php +++ b/tests/Unit/Application/UseCases/CampaignRequest/Reject/RejectCampaignRequestTest.php @@ -58,6 +58,7 @@ describe('reject campaign request use case', function (): void { new CouponPicture(new PicturePath('coupons/product.jpg'), new PicturePath('coupons/thumbnail.jpg')), new GS1('01234567890128', BarcodeFormat::EAN13), new CouponValidity(30, new DateTime()), + new CountryAuthorized(Country::FRANCE) ); }); @@ -69,7 +70,6 @@ describe('reject campaign request use case', function (): void { $id, new BrandCode('AAA01'), new Applicant('John', 'Doe', new Email('john.doe@example.com')), - new CountryAuthorized(Country::FRANCE), CampaignRequestType::CLUB, new PrintRules(maxPerCustomer: 3), $this->requestedCoupon, @@ -122,7 +122,6 @@ describe('reject campaign request use case', function (): void { $id, new BrandCode('AAA01'), new Applicant('John', 'Doe', new Email('john.doe@example.com')), - new CountryAuthorized(Country::FRANCE), CampaignRequestType::CLUB, new PrintRules(maxPerCustomer: 3), $this->requestedCoupon, diff --git a/tests/Unit/Domain/Models/Entities/CampaignRequestTest.php b/tests/Unit/Domain/Models/Entities/CampaignRequestTest.php index df36484..0f06b44 100644 --- a/tests/Unit/Domain/Models/Entities/CampaignRequestTest.php +++ b/tests/Unit/Domain/Models/Entities/CampaignRequestTest.php @@ -53,6 +53,7 @@ describe('campaign request', function (): void { new CouponPicture(new PicturePath('coupons/product.jpg'), new PicturePath('coupons/thumbnail.jpg')), new GS1('01234567890128', BarcodeFormat::EAN13), new CouponValidity(30, new DateTime()), + new CountryAuthorized(Country::FRANCE) ); }); @@ -61,7 +62,6 @@ describe('campaign request', function (): void { $id = CampaignRequestId::generate(); $code = new BrandCode('AAA01'); $applicant = new Applicant('John', 'Doe', new Email('john.doe@example.com')); - $country = new CountryAuthorized(Country::FRANCE); $campaignType = CampaignRequestType::CLUB; $printRules = new PrintRules(maxPerCustomer: 3); $requestedCoupon = $this->requestedCoupon; @@ -72,7 +72,6 @@ describe('campaign request', function (): void { $id, $code, $applicant, - $country, $campaignType, $printRules, $requestedCoupon, @@ -83,7 +82,6 @@ describe('campaign request', function (): void { expect($campaignRequest->id())->toBe($id) ->and($campaignRequest->code)->toBe($code) ->and($campaignRequest->applicant)->toBe($applicant) - ->and($campaignRequest->country)->toBe($country) ->and($campaignRequest->campaignType)->toBe($campaignType) ->and($campaignRequest->printRules)->toBe($printRules) ->and($campaignRequest->requestedCoupon)->toBe($requestedCoupon) @@ -98,7 +96,6 @@ describe('campaign request', function (): void { CampaignRequestId::generate(), new BrandCode('AAA01'), new Applicant('John', 'Doe', new Email('john.doe@example.com')), - new CountryAuthorized(Country::FRANCE), CampaignRequestType::CLUB, null, $this->requestedCoupon, @@ -118,7 +115,6 @@ describe('campaign request', function (): void { CampaignRequestId::generate(), new BrandCode('AAA01'), new Applicant('John', 'Doe', new Email('john.doe@example.com')), - new CountryAuthorized(Country::FRANCE), CampaignRequestType::CLUB, new PrintRules(maxPerCustomer: 3), $this->requestedCoupon, @@ -141,7 +137,6 @@ describe('campaign request', function (): void { CampaignRequestId::generate(), new BrandCode('AAA01'), new Applicant('John', 'Doe', new Email('john.doe@example.com')), - new CountryAuthorized(Country::FRANCE), CampaignRequestType::CLUB, new PrintRules(maxPerCustomer: 3), $this->requestedCoupon, @@ -160,7 +155,6 @@ describe('campaign request', function (): void { CampaignRequestId::generate(), new BrandCode('AAA01'), new Applicant('John', 'Doe', new Email('john.doe@example.com')), - new CountryAuthorized(Country::FRANCE), CampaignRequestType::CLUB, new PrintRules(maxPerCustomer: 3), $this->requestedCoupon, @@ -180,7 +174,6 @@ describe('campaign request', function (): void { CampaignRequestId::generate(), new BrandCode('AAA01'), new Applicant('John', 'Doe', new Email('john.doe@example.com')), - new CountryAuthorized(Country::FRANCE), CampaignRequestType::CLUB, new PrintRules(maxPerCustomer: 3), $this->requestedCoupon, @@ -202,7 +195,6 @@ describe('campaign request', function (): void { CampaignRequestId::generate(), new BrandCode('AAA01'), new Applicant('John', 'Doe', new Email('john.doe@example.com')), - new CountryAuthorized(Country::FRANCE), CampaignRequestType::CLUB, new PrintRules(maxPerCustomer: 3), $this->requestedCoupon, @@ -219,7 +211,6 @@ describe('campaign request', function (): void { ->and($rejected->id())->toBe($campaignRequest->id()) ->and($rejected->code)->toBe($campaignRequest->code) ->and($rejected->applicant)->toBe($campaignRequest->applicant) - ->and($rejected->country)->toBe($campaignRequest->country) ->and($rejected->campaignType)->toBe($campaignRequest->campaignType) ->and($rejected->printRules)->toBe($campaignRequest->printRules) ->and($rejected->requestedCoupon)->toBe($campaignRequest->requestedCoupon) @@ -233,7 +224,6 @@ describe('campaign request', function (): void { CampaignRequestId::generate(), new BrandCode('AAA01'), new Applicant('John', 'Doe', new Email('john.doe@example.com')), - new CountryAuthorized(Country::FRANCE), CampaignRequestType::CLUB, new PrintRules(maxPerCustomer: 3), $this->requestedCoupon, @@ -253,7 +243,6 @@ describe('campaign request', function (): void { CampaignRequestId::generate(), new BrandCode('AAA01'), new Applicant('John', 'Doe', new Email('john.doe@example.com')), - new CountryAuthorized(Country::FRANCE), CampaignRequestType::CLUB, new PrintRules(maxPerCustomer: 3), $this->requestedCoupon, @@ -276,7 +265,6 @@ describe('campaign request', function (): void { $id, new BrandCode('AAA01'), new Applicant('John', 'Doe', new Email('john.doe@example.com')), - new CountryAuthorized(Country::FRANCE), CampaignRequestType::CLUB, new PrintRules(maxPerCustomer: 3), $this->requestedCoupon, diff --git a/tests/Unit/Domain/Models/ValueObjects/RequestedCoupon/RequestedCouponTest.php b/tests/Unit/Domain/Models/ValueObjects/RequestedCoupon/RequestedCouponTest.php index f5107a9..ac4de15 100644 --- a/tests/Unit/Domain/Models/ValueObjects/RequestedCoupon/RequestedCouponTest.php +++ b/tests/Unit/Domain/Models/ValueObjects/RequestedCoupon/RequestedCouponTest.php @@ -19,7 +19,9 @@ use Domain\Models\ValueObjects\RequestedCoupon\RequestedCouponQuantity; use Domain\Models\ValueObjects\WarningThresholdQuantity; use Shared\Enums\Currency; use DateTime; +use Domain\Models\ValueObjects\CountryAuthorized; use Domain\Models\ValueObjects\RequestedCoupon\RequestedCoupon; +use Shared\Enums\Country; use Shared\ValueObjects\Money; covers(RequestedCoupon::class); @@ -41,7 +43,7 @@ describe('requested coupon', function (): void { $couponPicture = new CouponPicture(new PicturePath('coupons/product.jpg'), new PicturePath('coupons/thumbnail.jpg')); $gs1 = new GS1('01234567890128', BarcodeFormat::EAN13); $couponValidity = new CouponValidity(30, new DateTime()); - + $country = new CountryAuthorized(Country::FRANCE); // WHEN $coupon = new RequestedCoupon( $name, @@ -54,6 +56,7 @@ describe('requested coupon', function (): void { $couponPicture, $gs1, $couponValidity, + $country ); // THEN @@ -66,6 +69,7 @@ describe('requested coupon', function (): void { ->and($coupon->processingCode)->toBe($processingCode) ->and($coupon->couponPicture)->toBe($couponPicture) ->and($coupon->gs1)->toBe($gs1) - ->and($coupon->couponValidity)->toBe($couponValidity); + ->and($coupon->couponValidity)->toBe($couponValidity) + ->and($coupon->country)->toBe($country); }); });