79 lines
2.3 KiB
PHP
79 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects;
|
|
|
|
use Domain\Models\ValueObjects\PickupTimeSlot;
|
|
|
|
describe('PickupTimeSlot', function () {
|
|
it('can instantiate', function () {
|
|
// GIVEN
|
|
$startAt = new \DateTimeImmutable();
|
|
$duration = new \DateInterval('P1D');
|
|
|
|
// WHEN
|
|
$vo = new PickupTimeSlot($startAt, $duration);
|
|
|
|
// THEN
|
|
expect($vo)->toBeInstanceOf(PickupTimeSlot::class);
|
|
});
|
|
});
|
|
|
|
describe('PickupTimeSlot methods', function (): void {
|
|
it('returns getAt as immutable when passed mutable', function (): void {
|
|
// GIVEN
|
|
$at = new \DateTime();
|
|
$for = new \DateInterval('PT10M');
|
|
$vo = new PickupTimeSlot($at, $for);
|
|
// WHEN
|
|
$res = $vo->getAt();
|
|
// THEN
|
|
expect($res)->toBeInstanceOf(\DateTimeImmutable::class);
|
|
});
|
|
|
|
it('returns getAt as immutable when passed immutable', function (): void {
|
|
// GIVEN
|
|
$at = new \DateTimeImmutable();
|
|
$for = new \DateInterval('PT10M');
|
|
$vo = new PickupTimeSlot($at, $for);
|
|
// WHEN
|
|
$res = $vo->getAt();
|
|
// THEN
|
|
expect($res)->toBeInstanceOf(\DateTimeImmutable::class);
|
|
});
|
|
|
|
it('returns getFor', function (): void {
|
|
// GIVEN
|
|
$at = new \DateTimeImmutable();
|
|
$for = new \DateInterval('PT10M');
|
|
$vo = new PickupTimeSlot($at, $for);
|
|
// WHEN
|
|
$res = $vo->getFor();
|
|
// THEN
|
|
expect($res->i)->toBe(10);
|
|
});
|
|
|
|
it('returns getEndsAt', function (): void {
|
|
// GIVEN
|
|
$at = new \DateTimeImmutable('2024-01-01 10:00:00');
|
|
$for = new \DateInterval('PT10M');
|
|
$vo = new PickupTimeSlot($at, $for);
|
|
// WHEN
|
|
$res = $vo->getEndsAt();
|
|
// THEN
|
|
expect($res->format('H:i'))->toBe('10:10');
|
|
});
|
|
|
|
it('can be cast to string', function (): void {
|
|
// GIVEN
|
|
$at = new \DateTimeImmutable('2024-01-01 10:00:00', new \DateTimeZone('UTC'));
|
|
$for = new \DateInterval('PT10M');
|
|
$vo = new PickupTimeSlot($at, $for);
|
|
// WHEN
|
|
$res = (string) $vo;
|
|
// THEN
|
|
expect($res)->toContain('2024-01-01T10:00:00')
|
|
->and($res)->toContain('PT10M');
|
|
});
|
|
});
|