66 lines
1.9 KiB
PHP
66 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects;
|
|
|
|
use Carbon\CarbonImmutable;
|
|
use Domain\Enums\RepeatFrequency;
|
|
use Domain\Models\Entities\PickupExceptionOnDate;
|
|
use Domain\Models\ValueObjects\Entities\PickupExceptionId;
|
|
use Domain\Models\ValueObjects\ShopPickupOverride;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
describe('ShopPickupOverride', function (): void {
|
|
it('can instantiate correctly', function (): void {
|
|
// GIVEN
|
|
$exception = new PickupExceptionOnDate(
|
|
new PickupExceptionId(Uuid::uuid7()),
|
|
CarbonImmutable::now(),
|
|
'Label',
|
|
true,
|
|
RepeatFrequency::YEARLY,
|
|
false
|
|
);
|
|
|
|
$replacement = CarbonImmutable::now()->addDay();
|
|
$deadline = CarbonImmutable::now()->subDay();
|
|
|
|
// WHEN
|
|
$shopPickup = new ShopPickupOverride(
|
|
$exception,
|
|
$replacement,
|
|
$deadline
|
|
);
|
|
|
|
// THEN
|
|
expect($shopPickup->exception)->toBe($exception)
|
|
->and($shopPickup->replacementDate)->toBe($replacement)
|
|
->and($shopPickup->orderDeadlineAt)->toBe($deadline);
|
|
});
|
|
|
|
it('throws exception if orderDeadlineAt is not strictly before replacementDate', function (): void {
|
|
// GIVEN
|
|
$exception = new PickupExceptionOnDate(
|
|
new PickupExceptionId(Uuid::uuid7()),
|
|
CarbonImmutable::now(),
|
|
'Label',
|
|
true,
|
|
RepeatFrequency::YEARLY,
|
|
false
|
|
);
|
|
|
|
$replacement = CarbonImmutable::now();
|
|
$deadline = CarbonImmutable::now()->addDay();
|
|
|
|
// WHEN
|
|
$action = fn () => new ShopPickupOverride(
|
|
$exception,
|
|
$replacement,
|
|
$deadline
|
|
);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class, 'Order deadline must be strictly before the replacement date');
|
|
});
|
|
});
|