$path, 'fileContent' => "header\nvalue", ], $overrides); return new CsvImportFile(...$data); } it('can instantiate', function () { // GIVEN $path = tempnam(sys_get_temp_dir(), 'csv'); file_put_contents($path, 'dummy'); $content = "header\nvalue"; // WHEN $vo = new CsvImportFile( realPath: $path, fileContent: $content ); // THEN expect($vo)->toBeInstanceOf(CsvImportFile::class); unlink($path); }); it('throws exception if file path is not readable', function () { // GIVEN $invalidPath = '/invalid/path/to/file.csv'; // WHEN $action = fn () => getNewCsvImportFile($invalidPath); // THEN expect($action)->toThrow(\DomainException::class); }); it('throws exception if content is empty', function () { // GIVEN $path = tempnam(sys_get_temp_dir(), 'csv'); file_put_contents($path, 'dummy'); $emptyContent = ' '; // WHEN $action = function () use ($path, $emptyContent) { try { getNewCsvImportFile($path, [ 'fileContent' => $emptyContent, ]); } finally { if (file_exists($path)) { unlink($path); } } }; // THEN expect($action)->toThrow(\DomainException::class); }); });