ldc-boutique-cnc-sable/tests/Integration/WithApp/Helpers/DateHelperTest.php

86 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
use Illuminate\Support\Facades\Date;
use Shared\Helpers\DatesHelper;
describe('Date Helper', function (): void {
it('can verify a date is in between', function (): void {
// GIVEN
$now = Date::create(2025, 12, 25, 12, 0, 0);
$from = Date::createFromDate(2025, 12, 24);
$to = Date::createFromDate(2025, 12, 26);
// WHEN
Date::setTestNow($now);
$result = DatesHelper::isIn($from, $to);
// THEN
expect($result)->toBeTruthy();
});
it('returns true when both from and to are null (unbounded interval)', function (): void {
// GIVEN
$now = Date::create(2025, 12, 25, 12, 0, 0);
// WHEN
Date::setTestNow($now);
$result = DatesHelper::isIn(null, null);
// THEN
expect($result)->toBeTrue();
});
it('returns true when only from is set and now is after from', function (): void {
// GIVEN
$now = Date::create(2025, 12, 25, 12, 0, 0);
$from = Date::createFromDate(2025, 12, 24);
// WHEN
Date::setTestNow($now);
$result = DatesHelper::isIn($from, null);
// THEN
expect($result)->toBeTrue();
});
it('returns false when only from is set and now is before from', function (): void {
// GIVEN
$now = Date::create(2025, 12, 25, 12, 0, 0);
$from = Date::createFromDate(2025, 12, 26);
// WHEN
Date::setTestNow($now);
$result = DatesHelper::isIn($from, null);
// THEN
expect($result)->toBeFalse();
});
it('returns true when only to is set and now is before to', function (): void {
// GIVEN
$now = Date::create(2025, 12, 25, 12, 0, 0);
$to = Date::createFromDate(2025, 12, 26);
// WHEN
Date::setTestNow($now);
$result = DatesHelper::isIn(null, $to);
// THEN
expect($result)->toBeTrue();
});
it('returns false when only to is set and now is after to', function (): void {
// GIVEN
$now = Date::create(2025, 12, 25, 12, 0, 0);
$to = Date::createFromDate(2025, 12, 24);
// WHEN
Date::setTestNow($now);
$result = DatesHelper::isIn(null, $to);
// THEN
expect($result)->toBeFalse();
});
});