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..05af5aa 100644 --- a/src/Application/UseCases/CampaignRequest/Find/Output/CampaignRequestFound.php +++ b/src/Application/UseCases/CampaignRequest/Find/Output/CampaignRequestFound.php @@ -9,7 +9,6 @@ use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestType; use Domain\Models\Entities\Brand; 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; @@ -18,7 +17,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/Enums/Country.php b/src/Domain/Enums/Country.php deleted file mode 100644 index 4a719f2..0000000 --- a/src/Domain/Enums/Country.php +++ /dev/null @@ -1,586 +0,0 @@ -value => 'Afghanistan', - self::ALAND_ISLANDS->value => 'Åland Islands', - self::ALBANIA->value => 'Albania', - self::ALGERIA->value => 'Algeria', - self::AMERICAN_SAMOA->value => 'American Samoa', - self::ANDORRA->value => 'Andorra', - self::ANGOLA->value => 'Angola', - self::ANGUILLA->value => 'Anguilla', - self::ANTARCTICA->value => 'Antarctica', - self::ANTIGUA_AND_BARBUDA->value => 'Antigua and Barbuda', - self::ARGENTINA->value => 'Argentina', - self::ARMENIA->value => 'Armenia', - self::ARUBA->value => 'Aruba', - self::AUSTRALIA->value => 'Australia', - self::AUSTRIA->value => 'Austria', - self::AZERBAIJAN->value => 'Azerbaijan', - self::BAHRAIN->value => 'Bahrain', - self::BAHAMAS->value => 'Bahamas', - self::BANGLADESH->value => 'Bangladesh', - self::BARBADOS->value => 'Barbados', - self::BELARUS->value => 'Belarus', - self::BELGIUM->value => 'Belgium', - self::BELIZE->value => 'Belize', - self::BENIN->value => 'Benin', - self::BERMUDA->value => 'Bermuda', - self::BHUTAN->value => 'Bhutan', - self::BOLIVIA_PLURINATIONAL_STATE_OF->value => 'Bolivia, Plurinational State of', - self::BONAIRE_SINT_EUSTATIUS_AND_SABA->value => 'Bonaire, Sint Eustatius and Saba', - self::BOSNIA_AND_HERZEGOVINA->value => 'Bosnia and Herzegovina', - self::BOTSWANA->value => 'Botswana', - self::BOUVET_ISLAND->value => 'Bouvet Island', - self::BRAZIL->value => 'Brazil', - self::BRITISH_INDIAN_OCEAN_TERRITORY->value => 'British Indian Ocean Territory', - self::BRUNEI_DARUSSALAM->value => 'Brunei Darussalam', - self::BULGARIA->value => 'Bulgaria', - self::BURKINA_FASO->value => 'Burkina Faso', - self::BURUNDI->value => 'Burundi', - self::CAMBODIA->value => 'Cambodia', - self::CAMEROON->value => 'Cameroon', - self::CANADA->value => 'Canada', - self::CAPE_VERDE->value => 'Cape Verde', - self::CAYMAN_ISLANDS->value => 'Cayman Islands', - self::CENTRAL_AFRICAN_REPUBLIC->value => 'Central African Republic', - self::CHAD->value => 'Chad', - self::CHILE->value => 'Chile', - self::CHINA->value => 'China', - self::CHRISTMAS_ISLAND->value => 'Christmas Island', - self::COCOS_KEELING_ISLANDS->value => 'Cocos (Keeling) Islands', - self::COLOMBIA->value => 'Colombia', - self::COMOROS->value => 'Comoros', - self::CONGO->value => 'Congo', - self::CONGO_THE_DEMOCRATIC_REPUBLIC_OF_THE->value => 'Congo, the Democratic Republic of the', - self::COOK_ISLANDS->value => 'Cook Islands', - self::COSTA_RICA->value => 'Costa Rica', - self::COTE_DIVOIRE->value => 'Côte d\'Ivoire', - self::CROATIA->value => 'Croatia', - self::CUBA->value => 'Cuba', - self::CURACAO->value => 'Curaçao', - self::CYPRUS->value => 'Cyprus', - self::CZECH_REPUBLIC->value => 'Czech Republic', - self::DENMARK->value => 'Denmark', - self::DJIBOUTI->value => 'Djibouti', - self::DOMINICA->value => 'Dominica', - self::DOMINICAN_REPUBLIC->value => 'Dominican Republic', - self::ECUADOR->value => 'Ecuador', - self::EGYPT->value => 'Egypt', - self::EL_SALVADOR->value => 'El Salvador', - self::EQUATORIAL_GUINEA->value => 'Equatorial Guinea', - self::ERITREA->value => 'Eritrea', - self::ESTONIA->value => 'Estonia', - self::ETHIOPIA->value => 'Ethiopia', - self::FALKLAND_ISLANDS_MALVINAS->value => 'Falkland Islands (Malvinas)', - self::FAROE_ISLANDS->value => 'Faroe Islands', - self::FIJI->value => 'Fiji', - self::FINLAND->value => 'Finland', - self::FRANCE->value => 'France', - self::FRENCH_GUIANA->value => 'French Guiana', - self::FRENCH_POLYNESIA->value => 'French Polynesia', - self::FRENCH_SOUTHERN_TERRITORIES->value => 'French Southern Territories', - self::GABON->value => 'Gabon', - self::GAMBIA->value => 'Gambia', - self::GEORGIA->value => 'Georgia', - self::GERMANY->value => 'Germany', - self::GHANA->value => 'Ghana', - self::GIBRALTAR->value => 'Gibraltar', - self::GREECE->value => 'Greece', - self::GREENLAND->value => 'Greenland', - self::GRENADA->value => 'Grenada', - self::GUADELOUPE->value => 'Guadeloupe', - self::GUAM->value => 'Guam', - self::GUATEMALA->value => 'Guatemala', - self::GUERNSEY->value => 'Guernsey', - self::GUINEA->value => 'Guinea', - self::GUINEA_BISSAU->value => 'GuineaBissau', - self::GUYANA->value => 'Guyana', - self::HAITI->value => 'Haiti', - self::HEARD_ISLAND_AND_MCDONALD_ISLANDS->value => 'Heard Island and McDonald Islands', - self::HOLY_SEE_VATICAN_CITY_STATE->value => 'Holy See (Vatican City State)', - self::HONDURAS->value => 'Honduras', - self::HONG_KONG->value => 'Hong Kong', - self::HUNGARY->value => 'Hungary', - self::ICELAND->value => 'Iceland', - self::INDIA->value => 'India', - self::INDONESIA->value => 'Indonesia', - self::IRAN_ISLAMIC_REPUBLIC_OF->value => 'Iran, Islamic Republic of', - self::IRAQ->value => 'Iraq', - self::IRELAND->value => 'Ireland', - self::ISLE_OF_MAN->value => 'Isle of Man', - self::ISRAEL->value => 'Israel', - self::ITALY->value => 'Italy', - self::JAMAICA->value => 'Jamaica', - self::JAPAN->value => 'Japan', - self::JERSEY->value => 'Jersey', - self::JORDAN->value => 'Jordan', - self::KAZAKHSTAN->value => 'Kazakhstan', - self::KENYA->value => 'Kenya', - self::KIRIBATI->value => 'Kiribati', - self::KOREA_DEMOCRATIC_PEOPLES_REPUBLIC_OF->value => 'Korea, Democratic People\'s Republic of', - self::KOREA_REPUBLIC_OF->value => 'Korea, Republic of', - self::KUWAIT->value => 'Kuwait', - self::KYRGYZSTAN->value => 'Kyrgyzstan', - self::LAO_PEOPLES_DEMOCRATIC_REPUBLIC->value => 'Lao People\'s Democratic Republic', - self::LATVIA->value => 'Latvia', - self::LEBANON->value => 'Lebanon', - self::LESOTHO->value => 'Lesotho', - self::LIBERIA->value => 'Liberia', - self::LIBYA->value => 'Libya', - self::LIECHTENSTEIN->value => 'Liechtenstein', - self::LITHUANIA->value => 'Lithuania', - self::LUXEMBOURG->value => 'Luxembourg', - self::MACAO->value => 'Macao', - self::MACEDONIA_THE_FORMER_YUGOSLAV_REPUBLIC_OF->value => 'Macedonia, the Former Yugoslav Republic of', - self::MADAGASCAR->value => 'Madagascar', - self::MALAWI->value => 'Malawi', - self::MALAYSIA->value => 'Malaysia', - self::MALDIVES->value => 'Maldives', - self::MALI->value => 'Mali', - self::MALTA->value => 'Malta', - self::MARSHALL_ISLANDS->value => 'Marshall Islands', - self::MARTINIQUE->value => 'Martinique', - self::MAURITANIA->value => 'Mauritania', - self::MAURITIUS->value => 'Mauritius', - self::MAYOTTE->value => 'Mayotte', - self::MEXICO->value => 'Mexico', - self::MICRONESIA_FEDERATED_STATES_OF->value => 'Micronesia, Federated States of', - self::MOLDOVA_REPUBLIC_OF->value => 'Moldova, Republic of', - self::MONACO->value => 'Monaco', - self::MONGOLIA->value => 'Mongolia', - self::MONTENEGRO->value => 'Montenegro', - self::MONTSERRAT->value => 'Montserrat', - self::MOROCCO->value => 'Morocco', - self::MOZAMBIQUE->value => 'Mozambique', - self::MYANMAR->value => 'Myanmar', - self::NAMIBIA->value => 'Namibia', - self::NAURU->value => 'Nauru', - self::NEPAL->value => 'Nepal', - self::NETHERLANDS->value => 'Netherlands', - self::NEW_CALEDONIA->value => 'New Caledonia', - self::NEW_ZEALAND->value => 'New Zealand', - self::NICARAGUA->value => 'Nicaragua', - self::NIGER->value => 'Niger', - self::NIGERIA->value => 'Nigeria', - self::NIUE->value => 'Niue', - self::NORFOLK_ISLAND->value => 'Norfolk Island', - self::NORTHERN_MARIANA_ISLANDS->value => 'Northern Mariana Islands', - self::NORWAY->value => 'Norway', - self::OMAN->value => 'Oman', - self::PAKISTAN->value => 'Pakistan', - self::PALAU->value => 'Palau', - self::PALESTINE_STATE_OF->value => 'Palestine, State of', - self::PANAMA->value => 'Panama', - self::PAPUA_NEW_GUINEA->value => 'Papua New Guinea', - self::PARAGUAY->value => 'Paraguay', - self::PERU->value => 'Peru', - self::PHILIPPINES->value => 'Philippines', - self::PITCAIRN->value => 'Pitcairn', - self::POLAND->value => 'Poland', - self::PORTUGAL->value => 'Portugal', - self::PUERTO_RICO->value => 'Puerto Rico', - self::QATAR->value => 'Qatar', - self::REUNION->value => 'Réunion', - self::ROMANIA->value => 'Romania', - self::RUSSIAN_FEDERATION->value => 'Russian Federation', - self::RWANDA->value => 'Rwanda', - self::SAINT_BARTHELEMY->value => 'Saint Barthélemy', - self::SAINT_HELENA_ASCENSION_AND_TRISTAN_DA_CUNHA->value => 'Saint Helena, Ascension and Tristan da Cunha', - self::SAINT_KITTS_AND_NEVIS->value => 'Saint Kitts and Nevis', - self::SAINT_LUCIA->value => 'Saint Lucia', - self::SAINT_MARTIN_FRENCH_PART->value => 'Saint Martin (French part)', - self::SAINT_PIERRE_AND_MIQUELON->value => 'Saint Pierre and Miquelon', - self::SAINT_VINCENT_AND_THE_GRENADINES->value => 'Saint Vincent and the Grenadines', - self::SAMOA->value => 'Samoa', - self::SAN_MARINO->value => 'San Marino', - self::SAO_TOME_AND_PRINCIPE->value => 'Sao Tome and Principe', - self::SAUDI_ARABIA->value => 'Saudi Arabia', - self::SENEGAL->value => 'Senegal', - self::SERBIA->value => 'Serbia', - self::SEYCHELLES->value => 'Seychelles', - self::SIERRA_LEONE->value => 'Sierra Leone', - self::SINGAPORE->value => 'Singapore', - self::SINT_MAARTEN_DUTCH_PART->value => 'Sint Maarten (Dutch part)', - self::SLOVAKIA->value => 'Slovakia', - self::SLOVENIA->value => 'Slovenia', - self::SOLOMON_ISLANDS->value => 'Solomon Islands', - self::SOMALIA->value => 'Somalia', - self::SOUTH_AFRICA->value => 'South Africa', - self::SOUTH_GEORGIA_AND_THE_SOUTH_SANDWICH_ISLANDS->value => 'South Georgia and the South Sandwich Islands', - self::SOUTH_SUDAN->value => 'South Sudan', - self::SPAIN->value => 'Spain', - self::SRI_LANKA->value => 'Sri Lanka', - self::SUDAN->value => 'Sudan', - self::SURINAME->value => 'Suriname', - self::SVALBARD_AND_JAN_MAYEN->value => 'Svalbard and Jan Mayen', - self::SWAZILAND->value => 'Swaziland', - self::SWEDEN->value => 'Sweden', - self::SWITZERLAND->value => 'Switzerland', - self::SYRIAN_ARAB_REPUBLIC->value => 'Syrian Arab Republic', - self::TAIWAN_PROVINCE_OF_CHINA->value => 'Taiwan, Province of China', - self::TAJIKISTAN->value => 'Tajikistan', - self::TANZANIA_UNITED_REPUBLIC_OF->value => 'Tanzania, United Republic of', - self::THAILAND->value => 'Thailand', - self::TIMOR_LESTE->value => 'TimorLeste', - self::TOGO->value => 'Togo', - self::TOKELAU->value => 'Tokelau', - self::TONGA->value => 'Tonga', - self::TRINIDAD_AND_TOBAGO->value => 'Trinidad and Tobago', - self::TUNISIA->value => 'Tunisia', - self::TURKEY->value => 'Turkey', - self::TURKMENISTAN->value => 'Turkmenistan', - self::TURKS_AND_CAICOS_ISLANDS->value => 'Turks and Caicos Islands', - self::TUVALU->value => 'Tuvalu', - self::UGANDA->value => 'Uganda', - self::UKRAINE->value => 'Ukraine', - self::UNITED_ARAB_EMIRATES->value => 'United Arab Emirates', - self::UNITED_KINGDOM->value => 'United Kingdom', - self::UNITED_STATES->value => 'United States', - self::UNITED_STATES_MINOR_OUTLYING_ISLANDS->value => 'United States Minor Outlying Islands', - self::URUGUAY->value => 'Uruguay', - self::UZBEKISTAN->value => 'Uzbekistan', - self::VANUATU->value => 'Vanuatu', - self::VENEZUELA_BOLIVARIAN_REPUBLIC_OF->value => 'Venezuela, Bolivarian Republic of', - self::VIET_NAM->value => 'Viet Nam', - self::VIRGIN_ISLANDS_BRITISH->value => 'Virgin Islands, British', - self::VIRGIN_ISLANDS_US->value => 'Virgin Islands, U.S.', - self::WALLIS_AND_FUTUNA->value => 'Wallis and Futuna', - self::WESTERN_SAHARA->value => 'Western Sahara', - self::YEMEN->value => 'Yemen', - self::ZAMBIA->value => 'Zambia', - self::ZIMBABWE->value => 'Zimbabwe', - ]; - /** - * Custom added ISOCODES definition - */ - private const ISOCODES = [ - self::FRANCE->name => 'FR', - self::GUADELOUPE->name => 'GSP', - self::MARTINIQUE->name => 'MQ', - self::FRENCH_GUIANA->name => 'GF', - self::REUNION->name => 'RE', - self::SAINT_PIERRE_AND_MIQUELON->name => 'PM', - self::MAYOTTE->name => 'YT', - self::SAINT_BARTHELEMY->name => 'BL', - self::SAINT_MARTIN_FRENCH_PART->name => 'MF', - self::WALLIS_AND_FUTUNA->name => 'WF', - self::FRENCH_POLYNESIA->name => 'PF', - self::NEW_CALEDONIA->name => 'NC', - ]; - - /** - * Custom added Numerical ISOCODES definition - */ - private const ISOCODES_NUM = [ - self::FRANCE->name => 250, - self::GUADELOUPE->name => 312, - self::MARTINIQUE->name => 474, - self::FRENCH_GUIANA->name => 254, - self::REUNION->name => 638, - self::SAINT_PIERRE_AND_MIQUELON->name => 666, - self::MAYOTTE->name => 175, - self::SAINT_BARTHELEMY->name => 652, - self::SAINT_MARTIN_FRENCH_PART->name => 663, - self::WALLIS_AND_FUTUNA->name => 876, - self::FRENCH_POLYNESIA->name => 258, - self::NEW_CALEDONIA->name => 540, - ]; - - /** - * Get ISOCODE - */ - public function iso(): string - { - return self::ISOCODES[$this->name] ?? throw UnknownCountryIsoCodeException::fromCountry($this); - } - - /** - * Get ISOCODE NUM - */ - public function isoNum(): int - { - return self::ISOCODES_NUM[$this->name] ?? throw UnknownCountryIsoCodeException::fromCountry($this); - } - - /** - * Get ISOCODE - */ - public function isoCode(): ?string - { - return self::ISOCODES[$this->name] ?? null; - } - - /** - * Get enum ISOCODES - * - * @return array - */ - public static function toIsoCodes(): array - { - return self::ISOCODES; - } -} diff --git a/src/Domain/Models/Entities/Campaign.php b/src/Domain/Models/Entities/Campaign.php index f517879..197a7dd 100644 --- a/src/Domain/Models/Entities/Campaign.php +++ b/src/Domain/Models/Entities/Campaign.php @@ -9,9 +9,9 @@ use Domain\Models\ValueObjects\Campaign\CampaignCode; use Domain\Models\ValueObjects\Campaign\CampaignCoupon; use Domain\Models\ValueObjects\Campaign\CampaignId; use Domain\Models\ValueObjects\Campaign\CampaignName; -use Domain\Models\ValueObjects\CountryAuthorized; use Shared\DDD\Models\AggregateRoot; use Shared\DDD\Models\HasTimestampIdentifier; +use Shared\Enums\Country; /** * @implements \Shared\DDD\Models\AggregateRoot<\Domain\Models\ValueObjects\Campaign\CampaignId> @@ -25,7 +25,7 @@ final readonly class Campaign implements AggregateRoot, HasTimestampIdentifier public CampaignName $name, public bool $publication, public bool $printAllAtOnce, - public CountryAuthorized $availableIn, + public Country $availableIn, /** @var array $coupons */ public array $coupons, public BrandCode $brand, @@ -62,7 +62,7 @@ final readonly class Campaign implements AggregateRoot, HasTimestampIdentifier CampaignName $name, bool $publication, bool $printAllAtOnce, - CountryAuthorized $availableIn, + Country $availableIn, /** @var array $coupons */ array $coupons, BrandCode $brand, @@ -92,7 +92,7 @@ final readonly class Campaign implements AggregateRoot, HasTimestampIdentifier CampaignName $name, bool $publication, bool $printAllAtOnce, - CountryAuthorized $availableIn, + Country $availableIn, array $coupons, BrandCode $brand, ?\DateTimeInterface $updatedAt = null, 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 deleted file mode 100644 index d8e99d0..0000000 --- a/src/Domain/Models/ValueObjects/CountryAuthorized.php +++ /dev/null @@ -1,46 +0,0 @@ - */ - private const array AUTHORIZED = [ - Country::FRANCE, - Country::BELGIUM, - Country::LUXEMBOURG, - ]; - - 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)); - } - } - - /** - * @return list - */ - public static function authorizedCountries(): array - { - return self::AUTHORIZED; - } - - #[Override] - public function equals(mixed $other): bool - { - return $other instanceof self && $this->country === $other->country; - } - - public function __toString(): string - { - return $this->country->value; - } -} diff --git a/src/Domain/Models/ValueObjects/Coupon/CouponLegalInformation.php b/src/Domain/Models/ValueObjects/Coupon/CouponLegalInformation.php index 0a2a344..5f18054 100644 --- a/src/Domain/Models/ValueObjects/Coupon/CouponLegalInformation.php +++ b/src/Domain/Models/ValueObjects/Coupon/CouponLegalInformation.php @@ -4,14 +4,14 @@ declare(strict_types=1); namespace Domain\Models\ValueObjects\Coupon; -use Domain\Models\ValueObjects\CountryAuthorized; use Shared\DDD\Models\Equatable; +use Shared\Enums\Country; final readonly class CouponLegalInformation implements Equatable { public function __construct( public string $legalText, - public CountryAuthorized $forLocale + public Country $forLocale ) { if (mb_trim($this->legalText) === '') { throw new \DomainException('Legal text cannot be empty.'); diff --git a/src/Domain/Models/ValueObjects/Coupon/CouponProductInfo.php b/src/Domain/Models/ValueObjects/Coupon/CouponProductInfo.php index 853343f..2b00b78 100644 --- a/src/Domain/Models/ValueObjects/Coupon/CouponProductInfo.php +++ b/src/Domain/Models/ValueObjects/Coupon/CouponProductInfo.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace Domain\Models\ValueObjects\Coupon; -use Domain\Models\ValueObjects\CountryAuthorized; use Shared\DDD\Models\Equatable; +use Shared\Enums\Country; final readonly class CouponProductInfo implements Equatable { @@ -13,7 +13,7 @@ final readonly class CouponProductInfo implements Equatable public string $name, public string $range, public string $validityText, - public CountryAuthorized $forLocale + public Country $forLocale ) { $trimmedName = mb_trim($this->name); diff --git a/src/Domain/Models/ValueObjects/RequestedCoupon/RequestedCoupon.php b/src/Domain/Models/ValueObjects/RequestedCoupon/RequestedCoupon.php index 616c082..306e68b 100644 --- a/src/Domain/Models/ValueObjects/RequestedCoupon/RequestedCoupon.php +++ b/src/Domain/Models/ValueObjects/RequestedCoupon/RequestedCoupon.php @@ -25,8 +25,8 @@ final readonly class RequestedCoupon public MoneyAmount $moneyAmount, public ProcessingCode $processingCode, public CouponPicture $couponPicture, - public GS1 $gs1, - public CouponValidity $couponValidity, + public ?GS1 $gs1, + public CouponValidity $couponValidity ) { } } diff --git a/src/Domain/Exceptions/UnknownCountryIsoCodeException.php b/src/Shared/DDD/Exceptions/UnknownCountryIsoCodeException.php similarity index 87% rename from src/Domain/Exceptions/UnknownCountryIsoCodeException.php rename to src/Shared/DDD/Exceptions/UnknownCountryIsoCodeException.php index 6b566a3..263fc8e 100644 --- a/src/Domain/Exceptions/UnknownCountryIsoCodeException.php +++ b/src/Shared/DDD/Exceptions/UnknownCountryIsoCodeException.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Domain\Exceptions; +namespace Shared\DDD\Exceptions; -use Domain\Enums\Country; +use Shared\Enums\Country; final class UnknownCountryIsoCodeException extends \DomainException { diff --git a/src/Shared/Enums/Country.php b/src/Shared/Enums/Country.php new file mode 100644 index 0000000..218dd84 --- /dev/null +++ b/src/Shared/Enums/Country.php @@ -0,0 +1,11 @@ +requestedCoupon, @@ -101,7 +98,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 +114,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 +174,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 9413e3f..483a049 100644 --- a/tests/Unit/Application/UseCases/CampaignRequest/List/ListCampaignsRequestTest.php +++ b/tests/Unit/Application/UseCases/CampaignRequest/List/ListCampaignsRequestTest.php @@ -5,7 +5,8 @@ declare(strict_types=1); namespace Application\UseCases\CampaignRequest\List; use Domain\Enums\BarcodeFormat; -use Domain\Enums\Country; +use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestStatus; +use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestType; use Domain\Models\Entities\CampaignRequest; use Domain\Models\ValueObjects\Brand\BrandCode; use Domain\Models\ValueObjects\CampaignRequest\Applicant; @@ -14,9 +15,6 @@ use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestId; use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestSortClause; use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestSortCriteria; use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestSortField; -use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestStatus; -use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestType; -use Domain\Models\ValueObjects\CountryAuthorized; use Domain\Models\ValueObjects\Coupon\CouponValidity; use Domain\Models\ValueObjects\CouponName; use Domain\Models\ValueObjects\CouponPicture; @@ -76,7 +74,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 +83,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, @@ -135,7 +131,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, @@ -174,7 +169,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, @@ -184,7 +178,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 9f7ddab..9ba1a97 100644 --- a/tests/Unit/Application/UseCases/CampaignRequest/Reject/RejectCampaignRequestTest.php +++ b/tests/Unit/Application/UseCases/CampaignRequest/Reject/RejectCampaignRequestTest.php @@ -13,13 +13,11 @@ use Carbon\CarbonImmutable; use Domain\Enums\BarcodeFormat; use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestStatus; use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestType; -use Domain\Enums\Country; use Domain\Models\Entities\CampaignRequest; use Domain\Models\ValueObjects\Brand\BrandCode; use Domain\Models\ValueObjects\CampaignRequest\Applicant; use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestId; use Domain\Models\ValueObjects\CampaignRequest\RejectionReason; -use Domain\Models\ValueObjects\CountryAuthorized; use Domain\Models\ValueObjects\Coupon\CouponValidity; use Domain\Models\ValueObjects\CouponName; use Domain\Models\ValueObjects\CouponPicture; @@ -33,7 +31,6 @@ use Domain\Models\ValueObjects\ProcessingCode; use Domain\Models\ValueObjects\RequestedCoupon\RequestedCouponQuantity; use Domain\Models\ValueObjects\WarningThresholdQuantity; use Domain\Ports\Repositories\CampaignRequestRepository; -use Shared\DDD\UseCases\Input as BaseInput; use Shared\Enums\Currency; use DateTime; use Domain\Models\ValueObjects\RequestedCoupon\RequestedCoupon; @@ -70,7 +67,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, @@ -123,7 +119,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, @@ -144,28 +139,19 @@ describe('reject campaign request use case', function (): void { // THEN expect($action)->toThrow(\DomainException::class, 'Only a created campaign request can be rejected.'); }); -}); -describe('reject campaign request use case assertions', function (): void { - it('cannot build an input to reject a campaign request without a reason', function (): void { + it('never touches the repository when a rejection reason is missing', function (): void { + // GIVEN + $repository = \Mockery::mock(CampaignRequestRepository::class); + $repository->shouldNotReceive('findById'); + $repository->shouldNotReceive('save'); + + $useCase = new RejectCampaignRequest($repository); + // WHEN - $action = fn (): Input => new Input(id: CampaignRequestId::generate()); + $action = fn (): Output => $useCase->execute(new Input(id: CampaignRequestId::generate())); // THEN expect($action)->toThrow(\ArgumentCountError::class); }); - it('rejects an input of the wrong type', function (): void { - // GIVEN - $repository = \Mockery::mock(CampaignRequestRepository::class); - $useCase = new RejectCampaignRequest($repository); - $invalidInput = new class () implements BaseInput - { - }; - - // WHEN - $action = fn (): Output => $useCase->execute($invalidInput); - - // THEN - expect($action)->toThrow(\InvalidArgumentException::class); - }); }); diff --git a/tests/Unit/Domain/Enums/CountryTest.php b/tests/Unit/Domain/Enums/CountryTest.php index 5445fdc..5a6c7b8 100644 --- a/tests/Unit/Domain/Enums/CountryTest.php +++ b/tests/Unit/Domain/Enums/CountryTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Unit\Shared\Enums; -use Domain\Enums\Country; +use Shared\Enums\Country; covers(Country::class); @@ -12,8 +12,7 @@ describe('country', function (): void { it('has the expected cases with their backing values', function (): void { // THEN expect(Country::FRANCE->value)->toBe('france') - ->and(Country::BELGIUM->value)->toBe('belgium') - ->and(Country::LUXEMBOURG->value)->toBe('luxembourg'); + ->and(Country::BENELUX->value)->toBe('benelux'); }); it('exposes its case name', function (): void { diff --git a/tests/Unit/Domain/Models/Entities/CampaignRequestTest.php b/tests/Unit/Domain/Models/Entities/CampaignRequestTest.php index 837ae04..2217f6e 100644 --- a/tests/Unit/Domain/Models/Entities/CampaignRequestTest.php +++ b/tests/Unit/Domain/Models/Entities/CampaignRequestTest.php @@ -7,7 +7,6 @@ namespace Tests\Unit\Domain\Models\Entities; use Domain\Enums\BarcodeFormat; use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestStatus; use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestType; -use Domain\Enums\Country; use Domain\Models\Entities\CampaignRequest; use Domain\Models\ValueObjects\Brand\BrandCode; use Domain\Models\ValueObjects\CampaignRequest\Applicant; @@ -29,7 +28,6 @@ use DateTime; use Shared\ValueObjects\Email; use Shared\ValueObjects\Money; use Carbon\CarbonImmutable; -use Domain\Models\ValueObjects\CountryAuthorized; use Domain\Models\ValueObjects\RequestedCoupon\RequestedCoupon; use Domain\Models\ValueObjects\RequestedCoupon\RequestedCouponQuantity; use Domain\Models\ValueObjects\WarningThresholdQuantity; @@ -61,7 +59,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 +69,6 @@ describe('campaign request', function (): void { $id, $code, $applicant, - $country, $campaignType, $printRules, $requestedCoupon, @@ -83,7 +79,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 +93,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 +112,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 +134,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 +152,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 +171,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 +192,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 +208,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 +221,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 +240,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 +262,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/Entities/CampaignTest.php b/tests/Unit/Domain/Models/Entities/CampaignTest.php index 37511b7..25e96ba 100644 --- a/tests/Unit/Domain/Models/Entities/CampaignTest.php +++ b/tests/Unit/Domain/Models/Entities/CampaignTest.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace Tests\Unit\Domain\Models\Entities; use Carbon\CarbonImmutable; -use Domain\Enums\Country; +use Shared\Enums\Country; use Domain\Models\Entities\Campaign; use Domain\Models\Entities\Tag; use Domain\Models\ValueObjects\Brand\BrandCode; @@ -13,7 +13,6 @@ use Domain\Models\ValueObjects\Campaign\CampaignCode; use Domain\Models\ValueObjects\Campaign\CampaignCoupon; use Domain\Models\ValueObjects\Campaign\CampaignId; use Domain\Models\ValueObjects\Campaign\CampaignName; -use Domain\Models\ValueObjects\CountryAuthorized; use Domain\Models\ValueObjects\PrintRules; use Domain\Models\ValueObjects\ProcessingCode; use Domain\Models\ValueObjects\Stock\StockId; @@ -43,7 +42,7 @@ describe('campaign', function (): void { $name = new CampaignName('Name'); $publication = \boolval(0); $printAllAtOnce = \boolval(1); - $availableIn = new CountryAuthorized(Country::FRANCE); + $availableIn = Country::FRANCE; $coupons = [ new CampaignCoupon( new ProcessingCode('PC1'), @@ -88,7 +87,7 @@ describe('campaign', function (): void { $name = new CampaignName('Name'); $publication = \boolval(0); $printAllAtOnce = \boolval(1); - $availableIn = new CountryAuthorized(Country::FRANCE); + $availableIn = Country::FRANCE; $coupons = []; $brand = new BrandCode('AAA01'); @@ -116,7 +115,7 @@ describe('campaign', function (): void { $name = new CampaignName('Name'); $publication = \boolval(0); $printAllAtOnce = \boolval(1); - $availableIn = new CountryAuthorized(Country::FRANCE); + $availableIn = Country::FRANCE; $coupons = [ new CampaignCoupon( new ProcessingCode('PC1'), @@ -153,7 +152,7 @@ describe('campaign', function (): void { $name = new CampaignName('Name'); $publication = \boolval(0); $printAllAtOnce = \boolval(1); - $availableIn = new CountryAuthorized(Country::FRANCE); + $availableIn = Country::FRANCE; $coupons = [ new CampaignCoupon( new ProcessingCode('PC1'), @@ -196,7 +195,7 @@ describe('campaign', function (): void { $name = new CampaignName('Name'); $publication = \boolval(0); $printAllAtOnce = \boolval(1); - $availableIn = new CountryAuthorized(Country::FRANCE); + $availableIn = Country::FRANCE; $coupons = [ new CampaignCoupon( new ProcessingCode('PC1'), @@ -244,7 +243,7 @@ describe('campaign', function (): void { new CampaignName('Name'), \boolval(0), \boolval(1), - new CountryAuthorized(Country::FRANCE), + Country::FRANCE, [ new CampaignCoupon( new ProcessingCode('PC1'), @@ -270,7 +269,7 @@ describe('campaign', function (): void { $name = new CampaignName('Name'); $publication = \boolval(0); $printAllAtOnce = \boolval(1); - $availableIn = new CountryAuthorized(Country::FRANCE); + $availableIn = Country::FRANCE; $coupons = ['PC1']; $brand = new BrandCode('AAA01'); diff --git a/tests/Unit/Domain/Models/Entities/CouponTest.php b/tests/Unit/Domain/Models/Entities/CouponTest.php index f5971fb..97c243c 100644 --- a/tests/Unit/Domain/Models/Entities/CouponTest.php +++ b/tests/Unit/Domain/Models/Entities/CouponTest.php @@ -6,11 +6,10 @@ namespace Tests\Unit\Domain\Models\Entities; use Carbon\CarbonImmutable; use Domain\Enums\BarcodeFormat; -use Domain\Enums\Country; +use Shared\Enums\Country; use Domain\Models\Entities\Coupon; use Domain\Models\ValueObjects\Actor\ActorId; use Domain\Models\ValueObjects\Brand\BrandCode; -use Domain\Models\ValueObjects\CountryAuthorized; use Domain\Models\ValueObjects\Coupon\CouponAvailabilityCalendar; use Domain\Models\ValueObjects\Coupon\CouponDiffusion; use Domain\Models\ValueObjects\Coupon\CouponId; @@ -52,7 +51,7 @@ describe('coupon', function (): void { $legalInformation = [ new CouponLegalInformation( 'Lorem ipsum dolor sit amet consectetur adipiscing elit.', - new CountryAuthorized(Country::FRANCE) + Country::FRANCE ) ]; $code = new ProcessingCode('5425003944130'); @@ -114,7 +113,7 @@ describe('coupon', function (): void { $legalInformation = [ new CouponLegalInformation( 'Lorem ipsum dolor sit amet consectetur adipiscing elit.', - new CountryAuthorized(Country::FRANCE) + Country::FRANCE ) ]; $code = new ProcessingCode('5425003944130'); @@ -173,7 +172,7 @@ describe('coupon', function (): void { $legalInformation = [ new CouponLegalInformation( 'Lorem ipsum dolor sit amet consectetur adipiscing elit.', - new CountryAuthorized(Country::FRANCE) + Country::FRANCE ) ]; $code = new ProcessingCode('5425003944130'); @@ -221,7 +220,7 @@ describe('coupon', function (): void { $legalInformation = [ new CouponLegalInformation( 'Lorem ipsum dolor sit amet consectetur adipiscing elit.', - new CountryAuthorized(Country::FRANCE) + Country::FRANCE ) ]; $code = new ProcessingCode('5425003944130'); @@ -281,7 +280,7 @@ describe('coupon', function (): void { $legalInformation = [ new CouponLegalInformation( 'Lorem ipsum dolor sit amet consectetur adipiscing elit.', - new CountryAuthorized(Country::FRANCE) + Country::FRANCE ) ]; $code = new ProcessingCode('5425003944130'); @@ -342,7 +341,7 @@ describe('coupon', function (): void { new CouponDiffusion([new Period(new DateTime('2026-01-01'), new DateTime('2026-02-01'))]), new CouponAvailabilityCalendar([new Period(new DateTime('2026-08-25'), new DateTime('2026-10-31'))]), new CouponValidity(30, new DateTime('2026-11-30')), - [new CouponLegalInformation('Lorem ipsum dolor sit amet consectetur adipiscing elit.', new CountryAuthorized(Country::FRANCE))], + [new CouponLegalInformation('Lorem ipsum dolor sit amet consectetur adipiscing elit.', Country::FRANCE)], new ProcessingCode('5425003944130'), new BrandCode('AAA01'), ActorId::generate(), diff --git a/tests/Unit/Domain/Models/ValueObjects/CountryAuthorized.php b/tests/Unit/Domain/Models/ValueObjects/CountryAuthorized.php deleted file mode 100644 index 517d2c7..0000000 --- a/tests/Unit/Domain/Models/ValueObjects/CountryAuthorized.php +++ /dev/null @@ -1,65 +0,0 @@ -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'); - }); -}); diff --git a/tests/Unit/Domain/Models/ValueObjects/Coupon/CouponLegalInformationTest.php b/tests/Unit/Domain/Models/ValueObjects/Coupon/CouponLegalInformationTest.php index c3c8693..77fa49e 100644 --- a/tests/Unit/Domain/Models/ValueObjects/Coupon/CouponLegalInformationTest.php +++ b/tests/Unit/Domain/Models/ValueObjects/Coupon/CouponLegalInformationTest.php @@ -4,8 +4,7 @@ declare(strict_types=1); namespace Tests\Unit\Domain\Models\ValueObjects; -use Domain\Enums\Country; -use Domain\Models\ValueObjects\CountryAuthorized; +use Shared\Enums\Country; use Domain\Models\ValueObjects\Coupon\CouponLegalInformation; covers(CouponLegalInformation::class); @@ -14,7 +13,7 @@ describe('coupon legal information', function (): void { it('creates a valid coupon legal information', function (): void { // GIVEN $legalText = 'Lorem ipsum dolor sit amet consectetur adipiscing elit.'; - $forLocale = new CountryAuthorized(Country::FRANCE); + $forLocale = Country::FRANCE; // WHEN $couponLegalInformation = new CouponLegalInformation($legalText, $forLocale); @@ -27,7 +26,7 @@ describe('coupon legal information', function (): void { it('rejects invalid coupon legal information', function (): void { // GIVEN $legalText = ''; - $forLocale = new CountryAuthorized(Country::FRANCE); + $forLocale = Country::FRANCE; // GIVEN / THEN expect(fn (): CouponLegalInformation => new CouponLegalInformation($legalText, $forLocale))->toThrow(\DomainException::class); diff --git a/tests/Unit/Domain/Models/ValueObjects/Coupon/CouponProductInfoTest.php b/tests/Unit/Domain/Models/ValueObjects/Coupon/CouponProductInfoTest.php index 13ae8cd..293e8b6 100644 --- a/tests/Unit/Domain/Models/ValueObjects/Coupon/CouponProductInfoTest.php +++ b/tests/Unit/Domain/Models/ValueObjects/Coupon/CouponProductInfoTest.php @@ -4,8 +4,7 @@ declare(strict_types=1); namespace Tests\Unit\Domain\Models\ValueObjects; -use Domain\Enums\Country; -use Domain\Models\ValueObjects\CountryAuthorized; +use Shared\Enums\Country; use Domain\Models\ValueObjects\Coupon\CouponProductInfo; covers(CouponProductInfo::class); @@ -16,7 +15,7 @@ describe('coupon product info', function (): void { $name = 'Lorem ipsum'; $range = 'Lorem'; $validityText = 'Lorem ipsum dolor sit amet consectetur adipiscing elit.'; - $forLocale = new CountryAuthorized(Country::FRANCE); + $forLocale = Country::FRANCE; // WHEN $couponProductInfo = new CouponProductInfo($name, $range, $validityText, $forLocale); @@ -33,7 +32,7 @@ describe('coupon product info', function (): void { $name = ''; $range = ''; $validityText = ''; - $forLocale = new CountryAuthorized(Country::FRANCE); + $forLocale = Country::FRANCE; // GIVEN / THEN expect(fn (): CouponProductInfo => new CouponProductInfo($name, $range, $validityText, $forLocale))->toThrow(\DomainException::class); diff --git a/tests/Unit/Domain/Models/ValueObjects/RequestedCoupon/RequestedCouponTest.php b/tests/Unit/Domain/Models/ValueObjects/RequestedCoupon/RequestedCouponTest.php index f5107a9..2913dc3 100644 --- a/tests/Unit/Domain/Models/ValueObjects/RequestedCoupon/RequestedCouponTest.php +++ b/tests/Unit/Domain/Models/ValueObjects/RequestedCoupon/RequestedCouponTest.php @@ -41,7 +41,6 @@ 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()); - // WHEN $coupon = new RequestedCoupon( $name, @@ -68,4 +67,23 @@ describe('requested coupon', function (): void { ->and($coupon->gs1)->toBe($gs1) ->and($coupon->couponValidity)->toBe($couponValidity); }); + + it('hydrates a requested coupon without a GS1', function (): void { + // WHEN + $coupon = new RequestedCoupon( + new CouponName('Coupon A'), + new CouponProductName('Product A'), + new RequestedCouponQuantity(100), + new WarningThresholdQuantity(10), + new Period(new DateTime('2026-01-01'), new DateTime('2026-02-01')), + new MoneyAmount(new Money(Currency::EUR, 300)), + new ProcessingCode('PC1'), + new CouponPicture(new PicturePath('coupons/product.jpg'), new PicturePath('coupons/thumbnail.jpg')), + null, + new CouponValidity(30, new DateTime()), + ); + + // THEN + expect($coupon->gs1)->toBeNull(); + }); });