ldc-mesbr-app/tests/Unit/Domain/Models/ValueObjects/Coupon/CouponLegalInformationArrayTest.php

105 lines
3.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Models\ValueObjects\Coupon;
use Domain\Models\ValueObjects\Coupon\CouponLegalInformation;
use Domain\Models\ValueObjects\Coupon\CouponLegalInformationArray;
use Shared\Enums\Country;
covers(CouponLegalInformationArray::class);
describe('coupon legal information array', function (): void {
$franceInformation = new CouponLegalInformation('Lorem ipsum dolor sit amet consectetur adipiscing elit.', Country::FRANCE);
$beneluxInformation = new CouponLegalInformation('Lorem ipsum dolor sit amet consectetur adipiscing elit.', Country::BENELUX);
it('creates an array containing a France legal information', function () use ($franceInformation): void {
// GIVEN
$informations = [$franceInformation];
// WHEN
$array = new CouponLegalInformationArray($informations);
// THEN
expect($array->value)->toBe($informations);
});
it('accepts additional countries next to France', function () use ($franceInformation, $beneluxInformation): void {
// GIVEN
$informations = [$beneluxInformation, $franceInformation];
// WHEN
$array = new CouponLegalInformationArray($informations);
// THEN
expect($array->value)->toBe($informations);
});
it('rejects an empty array', function (): void {
// GIVEN / WHEN
$action = fn (): CouponLegalInformationArray => new CouponLegalInformationArray([]);
// THEN
expect($action)->toThrow(
\DomainException::class,
'CouponLegalInformations requires at least one CouponLegalInformation.',
);
});
it('rejects two legal informations for the same country', function () use ($franceInformation): void {
// GIVEN
$informations = [
$franceInformation,
new CouponLegalInformation('Lorem ipsum dolor sit amet consectetur adipiscing elit.', Country::FRANCE),
];
// WHEN
$action = fn (): CouponLegalInformationArray => new CouponLegalInformationArray($informations);
// THEN
expect($action)->toThrow(
\DomainException::class,
'Only one CouponLegalInformation is allowed per country, duplicate for FRANCE.',
);
});
it('rejects a non legal information element', function (): void {
// GIVEN / WHEN
$action = fn (): CouponLegalInformationArray => new CouponLegalInformationArray(['legal']);
// THEN
expect($action)->toThrow(
\DomainException::class,
'Value of CouponLegalInformationArray must be CouponLegalInformation instances.',
);
});
it('rejects a non legal information element mixed with valid ones', function () use ($franceInformation): void {
// GIVEN
$informations = [$franceInformation, 'legal'];
// WHEN
$action = fn (): CouponLegalInformationArray => new CouponLegalInformationArray($informations);
// THEN
expect($action)->toThrow(
\DomainException::class,
'Value of CouponLegalInformationArray must be CouponLegalInformation instances.',
);
});
it('rejects an array without France legal information', function () use ($beneluxInformation): void {
// GIVEN
$informations = [$beneluxInformation];
// WHEN
$action = fn (): CouponLegalInformationArray => new CouponLegalInformationArray($informations);
// THEN
expect($action)->toThrow(
\DomainException::class,
'CouponLegalInformations requires a CouponLegalInformation for France.',
);
});
});