138 lines
5.3 KiB
PHP
138 lines
5.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects\Coupon;
|
|
|
|
use Domain\Models\ValueObjects\Coupon\CouponCountryCoverage;
|
|
use Domain\Models\ValueObjects\Coupon\CouponLegalInformation;
|
|
use Domain\Models\ValueObjects\Coupon\CouponLegalInformationArray;
|
|
use Domain\Models\ValueObjects\Coupon\CouponValidityInformation;
|
|
use Domain\Models\ValueObjects\Coupon\CouponValidityInformationArray;
|
|
use Domain\Models\ValueObjects\ProcessingCode;
|
|
use Domain\Models\ValueObjects\ProcessingCodeArray;
|
|
use Shared\Enums\Country;
|
|
|
|
covers(CouponCountryCoverage::class);
|
|
|
|
describe('coupon country coverage', function (): void {
|
|
$franceCode = new ProcessingCode('5425003944130', Country::FRANCE);
|
|
$beneluxCode = new ProcessingCode('5425003944147', Country::BENELUX);
|
|
$franceValidity = new CouponValidityInformation('Lorem ipsum dolor sit amet consectetur adipiscing elit.', Country::FRANCE);
|
|
$beneluxValidity = new CouponValidityInformation('Lorem ipsum dolor sit amet consectetur adipiscing elit.', Country::BENELUX);
|
|
$franceLegal = new CouponLegalInformation('Lorem ipsum dolor sit amet consectetur adipiscing elit.', Country::FRANCE);
|
|
$beneluxLegal = new CouponLegalInformation('Lorem ipsum dolor sit amet consectetur adipiscing elit.', Country::BENELUX);
|
|
|
|
it('accepts a france only coupon', function () use ($franceCode, $franceValidity, $franceLegal): void {
|
|
// GIVEN / WHEN
|
|
$action = fn () => CouponCountryCoverage::assert(
|
|
new ProcessingCodeArray([$franceCode]),
|
|
new CouponValidityInformationArray([$franceValidity]),
|
|
new CouponLegalInformationArray([$franceLegal]),
|
|
);
|
|
|
|
// THEN
|
|
expect($action)->not->toThrow(\DomainException::class);
|
|
});
|
|
|
|
it('accepts a coupon fully covered for france and benelux', function () use (
|
|
$franceCode,
|
|
$beneluxCode,
|
|
$franceValidity,
|
|
$beneluxValidity,
|
|
$franceLegal,
|
|
$beneluxLegal,
|
|
): void {
|
|
// GIVEN / WHEN
|
|
$action = fn () => CouponCountryCoverage::assert(
|
|
new ProcessingCodeArray([$franceCode, $beneluxCode]),
|
|
new CouponValidityInformationArray([$franceValidity, $beneluxValidity]),
|
|
new CouponLegalInformationArray([$franceLegal, $beneluxLegal]),
|
|
);
|
|
|
|
// THEN
|
|
expect($action)->not->toThrow(\DomainException::class);
|
|
});
|
|
|
|
it('rejects a benelux processing code without benelux validity information', function () use (
|
|
$franceCode,
|
|
$beneluxCode,
|
|
$franceValidity,
|
|
$franceLegal,
|
|
$beneluxLegal,
|
|
): void {
|
|
// GIVEN / WHEN
|
|
$action = fn () => CouponCountryCoverage::assert(
|
|
new ProcessingCodeArray([$franceCode, $beneluxCode]),
|
|
new CouponValidityInformationArray([$franceValidity]),
|
|
new CouponLegalInformationArray([$franceLegal, $beneluxLegal]),
|
|
);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'A coupon requires validity information for BENELUX.');
|
|
});
|
|
|
|
it('rejects a benelux processing code without benelux legal information', function () use (
|
|
$franceCode,
|
|
$beneluxCode,
|
|
$franceValidity,
|
|
$beneluxValidity,
|
|
$franceLegal,
|
|
): void {
|
|
// GIVEN / WHEN
|
|
$action = fn () => CouponCountryCoverage::assert(
|
|
new ProcessingCodeArray([$franceCode, $beneluxCode]),
|
|
new CouponValidityInformationArray([$franceValidity, $beneluxValidity]),
|
|
new CouponLegalInformationArray([$franceLegal]),
|
|
);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'A coupon requires legal information for BENELUX.');
|
|
});
|
|
|
|
it('rejects validity information for a country where the coupon is not diffused', function () use (
|
|
$franceCode,
|
|
$franceValidity,
|
|
$beneluxValidity,
|
|
$franceLegal,
|
|
): void {
|
|
// GIVEN / WHEN
|
|
$action = fn () => CouponCountryCoverage::assert(
|
|
new ProcessingCodeArray([$franceCode]),
|
|
new CouponValidityInformationArray([$franceValidity, $beneluxValidity]),
|
|
new CouponLegalInformationArray([$franceLegal]),
|
|
);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'A coupon requires exactly one validity information per diffusion country.');
|
|
});
|
|
|
|
it('rejects legal information for a country where the coupon is not diffused', function () use (
|
|
$franceCode,
|
|
$franceValidity,
|
|
$franceLegal,
|
|
$beneluxLegal,
|
|
): void {
|
|
// GIVEN / WHEN
|
|
$action = fn () => CouponCountryCoverage::assert(
|
|
new ProcessingCodeArray([$franceCode]),
|
|
new CouponValidityInformationArray([$franceValidity]),
|
|
new CouponLegalInformationArray([$franceLegal, $beneluxLegal]),
|
|
);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'A coupon requires exactly one legal information per diffusion country.');
|
|
});
|
|
|
|
it('cannot be instantiated from the outside', function (): void {
|
|
// GIVEN
|
|
$reflection = new \ReflectionClass(CouponCountryCoverage::class);
|
|
$constructor = $reflection->getConstructor();
|
|
|
|
// WHEN
|
|
$constructor?->invoke($reflection->newInstanceWithoutConstructor());
|
|
|
|
// THEN
|
|
expect($constructor?->isPrivate())->toBeTrue();
|
|
});
|
|
});
|