ldc-arcadia-api/tests/Integration/Shared/Helpers/DateHelperTest.php
Jérémy Munsch 84e59314a0
test(Architecture): add namespaces to architecture test files and create integration test suite
- Added namespaces to various architecture test files for consistency.
- Created a new integration test suite in phpunit.xml.
2026-08-13 11:25:08 +02:00

69 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Integration\Shared\Helpers;
use Illuminate\Support\Facades\Date;
use Shared\Helpers\DatesHelper;
covers(DatesHelper::class);
afterEach(function () {
\Mockery::close();
Date::clearResolvedInstances();
});
describe('Date Helper', function (): void {
it('can parse a date time', function (): void {
// GIVEN
$date = '2025-12-25 12:10:23';
// WHEN
$result = DatesHelper::parseDateTime($date);
// THEN
expect($result)->toBeInstanceOf(\DateTimeInterface::class)
->and($result->format('Y-m-d'))->toBe('2025-12-25')
->and($result->format('H:i:s'))->toBe('12:10:23');
});
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('can verify a date is not in between', function (): void {
// GIVEN
$now = Date::create(2025, 12, 25, 12, 0, 0);
$from = Date::createFromDate(2025, 12, 26);
$to = Date::createFromDate(2025, 12, 27);
// WHEN
Date::setTestNow($now);
$result = DatesHelper::isIn($from, $to);
// THEN
expect($result)->toBeFalse();
});
it('can format a date time to RFC3339', function (): void {
// GIVEN
$date = '2025-12-25 12:10:23';
// WHEN
$result = DatesHelper::toRfc3339($date);
// THEN
expect($result)->toBe('2025-12-25T12:10:23+00:00');
});
});