test(DatesHelper): update date regex and add instantiation test
- Fixed regex for inverted French date format. - Added test to prevent direct instantiation of DatesHelper.
This commit is contained in:
parent
aaa39004bc
commit
8afc31c806
2 changed files with 13 additions and 3 deletions
|
|
@ -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$/';
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue