292 lines
10 KiB
PHP
292 lines
10 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects\RequestedCoupon;
|
|
|
|
use DateTime;
|
|
use Domain\Models\ValueObjects\Coupon\CouponLegalInformation;
|
|
use Domain\Models\ValueObjects\Coupon\CouponLegalInformationArray;
|
|
use Domain\Models\ValueObjects\Coupon\CouponName;
|
|
use Domain\Models\ValueObjects\Coupon\CouponPicture;
|
|
use Domain\Models\ValueObjects\Coupon\CouponProductArray;
|
|
use Domain\Models\ValueObjects\Coupon\CouponValidityInformation;
|
|
use Domain\Models\ValueObjects\Coupon\CouponValidityInformationArray;
|
|
use Domain\Models\ValueObjects\IncoCode;
|
|
use Domain\Models\ValueObjects\MoneyAmount;
|
|
use Domain\Models\ValueObjects\Period;
|
|
use Domain\Models\ValueObjects\PicturePath;
|
|
use Domain\Models\ValueObjects\PrintRules;
|
|
use Domain\Models\ValueObjects\ProcessingCode;
|
|
use Domain\Models\ValueObjects\ProcessingCodeArray;
|
|
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCoupon;
|
|
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCouponQuantity;
|
|
use Shared\Enums\Country;
|
|
use Shared\Enums\Currency;
|
|
use Shared\ValueObjects\Money;
|
|
|
|
covers(RequestedCoupon::class);
|
|
|
|
describe('requested coupon', function (): void {
|
|
$couponName = new CouponName('Coupon A');
|
|
$quantity = new RequestedCouponQuantity(100);
|
|
$diffusion = new Period(new DateTime('2026-01-01'), new DateTime('2026-02-01'));
|
|
$moneyAmount = new MoneyAmount(new Money(Currency::EUR, 300));
|
|
$couponPicture = new CouponPicture(
|
|
new PicturePath('files/product.jpg'),
|
|
new PicturePath('files/thumbnail.jpg'),
|
|
new PicturePath('files/mobileThumbnail.jpg')
|
|
);
|
|
|
|
$franceProcessingCode = new ProcessingCode('5425003944130', Country::FRANCE);
|
|
$beneluxProcessingCode = new ProcessingCode('5425003944147', Country::BENELUX);
|
|
$couponProcessingCodes = new ProcessingCodeArray([
|
|
$franceProcessingCode,
|
|
$beneluxProcessingCode,
|
|
]);
|
|
|
|
$franceValidityInformation = new CouponValidityInformation(
|
|
'Lorem ipsum dolor sit amet consectetur adipiscing elit.',
|
|
Country::FRANCE
|
|
);
|
|
$beneluxValidityInformation = new CouponValidityInformation(
|
|
'Lorem ipsum dolor sit amet consectetur adipiscing elit.',
|
|
Country::BENELUX
|
|
);
|
|
$couponValidityInformations = new CouponValidityInformationArray([
|
|
$franceValidityInformation,
|
|
$beneluxValidityInformation,
|
|
]);
|
|
|
|
$franceLegalInformation = new CouponLegalInformation(
|
|
'Lorem ipsum dolor sit amet consectetur adipiscing elit.',
|
|
Country::FRANCE
|
|
);
|
|
$beneluxLegalInformation = new CouponLegalInformation(
|
|
'Lorem ipsum dolor sit amet consectetur adipiscing elit.',
|
|
Country::BENELUX
|
|
);
|
|
$couponLegalInformations = new CouponLegalInformationArray([
|
|
$franceLegalInformation,
|
|
$beneluxLegalInformation,
|
|
]);
|
|
|
|
$couponProducts = new CouponProductArray([
|
|
new IncoCode(35784),
|
|
new IncoCode(15522),
|
|
]);
|
|
$printRules = new PrintRules(maxPerCustomer: 3);
|
|
|
|
it('hydrates a requested coupon with all its fields', function () use (
|
|
$couponName,
|
|
$quantity,
|
|
$diffusion,
|
|
$moneyAmount,
|
|
$couponPicture,
|
|
$couponProcessingCodes,
|
|
$couponValidityInformations,
|
|
$couponLegalInformations,
|
|
$couponProducts,
|
|
$printRules,
|
|
): void {
|
|
// GIVEN / WHEN
|
|
$coupon = new RequestedCoupon(
|
|
couponName: $couponName,
|
|
quantity: $quantity,
|
|
diffusion: $diffusion,
|
|
moneyAmount: $moneyAmount,
|
|
couponPicture: $couponPicture,
|
|
couponProcessingCodes: $couponProcessingCodes,
|
|
couponValidityInformations: $couponValidityInformations,
|
|
couponLegalInformations: $couponLegalInformations,
|
|
couponProducts: $couponProducts,
|
|
printRules: $printRules,
|
|
);
|
|
|
|
// THEN
|
|
expect($coupon->couponName)->toBe($couponName)
|
|
->and($coupon->quantity)->toBe($quantity)
|
|
->and($coupon->diffusion)->toBe($diffusion)
|
|
->and($coupon->moneyAmount)->toBe($moneyAmount)
|
|
->and($coupon->couponPicture)->toBe($couponPicture)
|
|
->and($coupon->couponProcessingCodes)->toBe($couponProcessingCodes)
|
|
->and($coupon->couponValidityInformations)->toBe($couponValidityInformations)
|
|
->and($coupon->couponLegalInformations)->toBe($couponLegalInformations)
|
|
->and($coupon->couponProducts)->toBe($couponProducts)
|
|
->and($coupon->printRules)->toBe($printRules);
|
|
});
|
|
|
|
it('hydrates a requested coupon without products', function () use (
|
|
$couponName,
|
|
$quantity,
|
|
$diffusion,
|
|
$moneyAmount,
|
|
$couponPicture,
|
|
$couponProcessingCodes,
|
|
$couponValidityInformations,
|
|
$couponLegalInformations,
|
|
$printRules,
|
|
): void {
|
|
// GIVEN / WHEN
|
|
$coupon = new RequestedCoupon(
|
|
couponName: $couponName,
|
|
quantity: $quantity,
|
|
diffusion: $diffusion,
|
|
moneyAmount: $moneyAmount,
|
|
couponPicture: $couponPicture,
|
|
couponProcessingCodes: $couponProcessingCodes,
|
|
couponValidityInformations: $couponValidityInformations,
|
|
couponLegalInformations: $couponLegalInformations,
|
|
couponProducts: new CouponProductArray(),
|
|
printRules: $printRules,
|
|
);
|
|
|
|
// THEN
|
|
expect($coupon->couponProducts->value)->toBe([])
|
|
->and($coupon->printRules)->toBe($printRules);
|
|
});
|
|
|
|
it('hydrates a requested coupon without print rules', function () use (
|
|
$couponName,
|
|
$quantity,
|
|
$diffusion,
|
|
$moneyAmount,
|
|
$couponPicture,
|
|
$couponProcessingCodes,
|
|
$couponValidityInformations,
|
|
$couponLegalInformations,
|
|
$couponProducts,
|
|
): void {
|
|
// GIVEN / WHEN
|
|
$coupon = new RequestedCoupon(
|
|
couponName: $couponName,
|
|
quantity: $quantity,
|
|
diffusion: $diffusion,
|
|
moneyAmount: $moneyAmount,
|
|
couponPicture: $couponPicture,
|
|
couponProcessingCodes: $couponProcessingCodes,
|
|
couponValidityInformations: $couponValidityInformations,
|
|
couponLegalInformations: $couponLegalInformations,
|
|
couponProducts: $couponProducts,
|
|
);
|
|
|
|
// THEN
|
|
expect($coupon->printRules)->toBeNull()
|
|
->and($coupon->couponProducts)->toBe($couponProducts);
|
|
});
|
|
|
|
it('accepts a france only coupon', function () use (
|
|
$couponName,
|
|
$quantity,
|
|
$diffusion,
|
|
$moneyAmount,
|
|
$couponPicture,
|
|
$franceProcessingCode,
|
|
$franceValidityInformation,
|
|
$franceLegalInformation,
|
|
$couponProducts,
|
|
): void {
|
|
// GIVEN / WHEN
|
|
$coupon = new RequestedCoupon(
|
|
couponName: $couponName,
|
|
quantity: $quantity,
|
|
diffusion: $diffusion,
|
|
moneyAmount: $moneyAmount,
|
|
couponPicture: $couponPicture,
|
|
couponProcessingCodes: new ProcessingCodeArray([
|
|
$franceProcessingCode,
|
|
]),
|
|
couponValidityInformations: new CouponValidityInformationArray([
|
|
$franceValidityInformation,
|
|
]),
|
|
couponLegalInformations: new CouponLegalInformationArray([
|
|
$franceLegalInformation,
|
|
]),
|
|
couponProducts: $couponProducts,
|
|
);
|
|
|
|
// THEN
|
|
expect($coupon)->toBeInstanceOf(RequestedCoupon::class);
|
|
});
|
|
|
|
it('throws when there is no processing code for france', function () use (
|
|
$couponName,
|
|
$quantity,
|
|
$diffusion,
|
|
$moneyAmount,
|
|
$couponPicture,
|
|
$beneluxProcessingCode,
|
|
$couponValidityInformations,
|
|
$couponLegalInformations,
|
|
$couponProducts,
|
|
): void {
|
|
// GIVEN / WHEN / THEN
|
|
expect(fn (): RequestedCoupon => new RequestedCoupon(
|
|
couponName: $couponName,
|
|
quantity: $quantity,
|
|
diffusion: $diffusion,
|
|
moneyAmount: $moneyAmount,
|
|
couponPicture: $couponPicture,
|
|
couponProcessingCodes: new ProcessingCodeArray([
|
|
$beneluxProcessingCode,
|
|
]),
|
|
couponValidityInformations: $couponValidityInformations,
|
|
couponLegalInformations: $couponLegalInformations,
|
|
couponProducts: $couponProducts,
|
|
))->toThrow(\DomainException::class, 'ProcessingCodes requires a ProcessingCode for France.');
|
|
});
|
|
|
|
it('throws when a benelux processing code has no benelux validity information', function () use (
|
|
$couponName,
|
|
$quantity,
|
|
$diffusion,
|
|
$moneyAmount,
|
|
$couponPicture,
|
|
$couponProcessingCodes,
|
|
$franceValidityInformation,
|
|
$couponLegalInformations,
|
|
$couponProducts,
|
|
): void {
|
|
// GIVEN / WHEN / THEN
|
|
expect(fn (): RequestedCoupon => new RequestedCoupon(
|
|
couponName: $couponName,
|
|
quantity: $quantity,
|
|
diffusion: $diffusion,
|
|
moneyAmount: $moneyAmount,
|
|
couponPicture: $couponPicture,
|
|
couponProcessingCodes: $couponProcessingCodes,
|
|
couponValidityInformations: new CouponValidityInformationArray([
|
|
$franceValidityInformation,
|
|
]),
|
|
couponLegalInformations: $couponLegalInformations,
|
|
couponProducts: $couponProducts,
|
|
))->toThrow(\DomainException::class, 'A coupon requires validity information for BENELUX.');
|
|
});
|
|
|
|
it('throws when a benelux processing code has no benelux legal information', function () use (
|
|
$couponName,
|
|
$quantity,
|
|
$diffusion,
|
|
$moneyAmount,
|
|
$couponPicture,
|
|
$couponProcessingCodes,
|
|
$couponValidityInformations,
|
|
$franceLegalInformation,
|
|
$couponProducts,
|
|
): void {
|
|
// GIVEN / WHEN / THEN
|
|
expect(fn (): RequestedCoupon => new RequestedCoupon(
|
|
couponName: $couponName,
|
|
quantity: $quantity,
|
|
diffusion: $diffusion,
|
|
moneyAmount: $moneyAmount,
|
|
couponPicture: $couponPicture,
|
|
couponProcessingCodes: $couponProcessingCodes,
|
|
couponValidityInformations: $couponValidityInformations,
|
|
couponLegalInformations: new CouponLegalInformationArray([
|
|
$franceLegalInformation,
|
|
]),
|
|
couponProducts: $couponProducts,
|
|
))->toThrow(\DomainException::class, 'A coupon requires legal information for BENELUX.');
|
|
});
|
|
});
|