- Added EmployeesImportResults class to encapsulate import results. - Created ImportEmployees action to handle CSV import and upsert employees. - Introduced ImportEmployeesInput class for input validation. - Developed EmployeeCsvReaderService for reading and parsing CSV files. - Implemented EmployeeCsvImportLine to map CSV rows to employee data. - Added EnhancedCsvReader for improved CSV handling. - Updated composer.json to include fusonic/csv-reader dependency. - Created tests for the new employee import functionality.
45 lines
1.5 KiB
PHP
45 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Services\EmployeeCsvImportLine;
|
|
|
|
describe('EmployeeCsvImportLine', function (): void {
|
|
it('parses dates and normalizes service code', function (): void {
|
|
// GIVEN
|
|
$line = new EmployeeCsvImportLine();
|
|
|
|
// WHEN
|
|
$line->setStartDate('01/10/2026');
|
|
$line->setEndDate('');
|
|
$line->setExpectedEndDate('15/10/2026');
|
|
$line->setService('LDCCAV030');
|
|
|
|
// THEN
|
|
expect($line->startDate)->toBeInstanceOf(\DateTimeImmutable::class)
|
|
->and($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 EmployeeCsvImportLine();
|
|
|
|
// 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 EmployeeCsvImportLine();
|
|
|
|
// WHEN + THEN
|
|
expect(fn () => $line->setEndDate('31-12-2026'))
|
|
->toThrow(\InvalidArgumentException::class, 'Invalid date format: 31-12-2026');
|
|
});
|
|
});
|
|
|