- 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.
50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Cqs\Actions\Employee\ImportEmployeesInput;
|
|
|
|
describe('ImportEmployeesInput', function (): void {
|
|
it('accepts a readable stream', function (): void {
|
|
// GIVEN
|
|
$filePath = tempnam(sys_get_temp_dir(), 'employees-csv-');
|
|
expect($filePath)->not->toBeFalse();
|
|
file_put_contents($filePath, 'header');
|
|
|
|
$stream = fopen($filePath, 'r');
|
|
expect($stream)->not->toBeFalse();
|
|
|
|
// WHEN
|
|
$input = new ImportEmployeesInput($stream);
|
|
|
|
// THEN
|
|
expect($input->inputStream)->toBe($stream);
|
|
|
|
fclose($stream);
|
|
unlink($filePath);
|
|
});
|
|
|
|
it('throws when stream is not readable', function (): void {
|
|
// GIVEN
|
|
$filePath = tempnam(sys_get_temp_dir(), 'employees-csv-');
|
|
expect($filePath)->not->toBeFalse();
|
|
$stream = fopen($filePath, 'w');
|
|
expect($stream)->not->toBeFalse();
|
|
|
|
// WHEN + THEN
|
|
expect(fn () => new ImportEmployeesInput($stream))
|
|
->toThrow(\InvalidArgumentException::class, 'Input stream must be readable.');
|
|
|
|
fclose($stream);
|
|
unlink($filePath);
|
|
});
|
|
|
|
it('throws when input is not a resource', function (): void {
|
|
// GIVEN
|
|
$notAStream = 'employees.csv';
|
|
|
|
// WHEN + THEN
|
|
expect(fn () => new ImportEmployeesInput($notAStream))
|
|
->toThrow(\InvalidArgumentException::class);
|
|
});
|
|
});
|