From 8afc31c806998bcba7b1f6180e18d581b142f66a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Thu, 13 Aug 2026 13:11:55 +0200 Subject: [PATCH] test(DatesHelper): update date regex and add instantiation test - Fixed regex for inverted French date format. - Added test to prevent direct instantiation of DatesHelper. --- src/Shared/Helpers/DatesHelper.php | 2 +- .../Integration/Shared/Helpers/DateHelperTest.php | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Shared/Helpers/DatesHelper.php b/src/Shared/Helpers/DatesHelper.php index 458a8d3..c890303 100644 --- a/src/Shared/Helpers/DatesHelper.php +++ b/src/Shared/Helpers/DatesHelper.php @@ -11,7 +11,7 @@ final class DatesHelper { private const string FRENCH_DATE_REGEX = '/^\d{4}-\d{2}-\d{2}$/'; - private const string FRENCH_DATE_INVERT_REGEX = '/^\d{2}-\d{2}\d{4}$/'; + private const string FRENCH_DATE_INVERT_REGEX = '/^\d{2}-\d{2}-\d{4}$/'; private const string ISO8601_REGEX = '/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/'; diff --git a/tests/Integration/Shared/Helpers/DateHelperTest.php b/tests/Integration/Shared/Helpers/DateHelperTest.php index e2d8e14..b21a355 100644 --- a/tests/Integration/Shared/Helpers/DateHelperTest.php +++ b/tests/Integration/Shared/Helpers/DateHelperTest.php @@ -10,10 +10,19 @@ use Shared\Helpers\DatesHelper; covers(DatesHelper::class); afterEach(function (): void { + \Mockery::close(); CarbonImmutable::setTestNow(); }); describe('Date Helper Integration Tests', function (): void { + it('prevents direct instantiation', function (): void { + // GIVEN + $reflection = new \ReflectionClass(DatesHelper::class); + + // WHEN & THEN + expect(fn () => $reflection->newInstance()) + ->toThrow(\ReflectionException::class); + }); it('can parse various date formats', function (string $input, string $expectedFormat): void { // GIVEN & WHEN @@ -28,7 +37,8 @@ describe('Date Helper Integration Tests', function (): void { ['25-12-2025', '2025-12-25'], ['2025-12-25T12:10:23Z', '2025-12-25'], ['2025-12-25T12:10:23+02:00', '2025-12-25'], - ['2025-12-25T12:10:23.123456Z', '2025-12-25'], + ['2025-12-25T12:10:23.123456+02:00', '2025-12-25'], + ['2025/12/25', '2025-12-25'], ]); it('throws InvalidArgumentException for unparseable date strings', function (): void { @@ -37,7 +47,7 @@ describe('Date Helper Integration Tests', function (): void { // WHEN & THEN expect(fn () => DatesHelper::parseDateTime($invalidDate)) - ->toThrow(\InvalidArgumentException::class); + ->toThrow(\InvalidArgumentException::class, 'Unrecognized date/time format: not-a-real-date-string'); }); it('handles isIn date boundary checks correctly', function (): void {