45 lines
1.5 KiB
PHP
45 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\App\Services;
|
|
|
|
use App\Services\EmployeeCsvImportLineService;
|
|
|
|
describe('EmployeeCsvImportLineService', function (): void {
|
|
it('parses dates and normalizes service code', function (): void {
|
|
// GIVEN
|
|
$line = new EmployeeCsvImportLineService();
|
|
|
|
// WHEN
|
|
$line->setStartDate('01/10/2026');
|
|
$line->setEndDate('');
|
|
$line->setExpectedEndDate('15/10/2026');
|
|
$line->setService('LDCCAV030');
|
|
|
|
// THEN
|
|
expect($line->startDate->format('Y-m-d'))->toBe('2026-10-01')
|
|
->and($line->endDate)->toBeNull()
|
|
->and($line->expectedEndDate)->toBeInstanceOf(\DateTimeImmutable::class)
|
|
->and($line->expectedEndDate?->format('Y-m-d'))->toBe('2026-10-15')
|
|
->and($line->service)->toBe('030');
|
|
});
|
|
|
|
it('throws when mandatory start date has invalid format', function (): void {
|
|
// GIVEN
|
|
$line = new EmployeeCsvImportLineService();
|
|
|
|
// WHEN + THEN
|
|
expect(fn () => $line->setStartDate('2026-10-01'))
|
|
->toThrow(\InvalidArgumentException::class, 'Invalid date format: 2026-10-01');
|
|
});
|
|
|
|
it('throws when optional end date has invalid format', function (): void {
|
|
// GIVEN
|
|
$line = new EmployeeCsvImportLineService();
|
|
|
|
// WHEN + THEN
|
|
expect(fn () => $line->setEndDate('2026-12-31'))
|
|
->toThrow(\InvalidArgumentException::class, 'Invalid date format: 2026-12-31');
|
|
});
|
|
});
|