test(DateHelper): add integration tests for date parsing and formatting

This commit introduces integration tests for the DatesHelper class,
ensuring correct functionality for date parsing, range verification,
and RFC3339 formatting.
This commit is contained in:
Jérémy Munsch 2026-08-13 10:24:11 +02:00
parent 57756ce6ae
commit eacfd828f0
Signed by: forge-joniko
GPG key ID: D7EFE2F5CB6CC0E4

View file

@ -0,0 +1,67 @@
<?php
declare(strict_types=1);
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');
});
});