@@ -273,25 +273,16 @@ protected function csvToArray($content, $entityId = null)
273273 */
274274 protected function importDataForMediaTest (string $ fileName , int $ expectedErrors = 0 )
275275 {
276- $ rootDirectory = $ this ->objectManager ->get (TargetDirectory::class)->getDirectoryWrite (DirectoryList::ROOT );
277276 $ filesystem = $ this ->objectManager ->get (Filesystem::class);
278- $ importExportDirectory = $ filesystem ->getDirectoryWrite (DirectoryList::VAR_IMPORT_EXPORT );
279-
280- $ dirPath = $ importExportDirectory ->getAbsolutePath ('import ' );
281- $ driver = $ importExportDirectory ->getDriver ();
282- $ driver ->createDirectory ($ dirPath );
283- $ driver ->filePutContents (
284- $ dirPath . DIRECTORY_SEPARATOR . $ fileName ,
285- file_get_contents (__DIR__ . DIRECTORY_SEPARATOR . '_files ' . DIRECTORY_SEPARATOR . $ fileName )
286- );
287-
277+ $ directory = $ filesystem ->getDirectoryWrite (DirectoryList::ROOT );
288278 $ source = $ this ->objectManager ->create (
289279 \Magento \ImportExport \Model \Import \Source \Csv::class,
290280 [
291- 'file ' => $ dirPath . DIRECTORY_SEPARATOR . $ fileName ,
292- 'directory ' => $ importExportDirectory
281+ 'file ' => __DIR__ . ' /_files/ ' . $ fileName ,
282+ 'directory ' => $ directory
293283 ]
294284 );
285+ $ rootDirectory = $ this ->objectManager ->get (TargetDirectory::class)->getDirectoryWrite (DirectoryList::ROOT );
295286 $ this ->_model ->setParameters (
296287 [
297288 'behavior ' => \Magento \ImportExport \Model \Import::BEHAVIOR_APPEND ,
@@ -341,7 +332,6 @@ function ($output, $error) {
341332 ''
342333 )
343334 );
344- $ source ->destruct ();
345335 }
346336
347337 /**
@@ -387,38 +377,30 @@ protected function importFile(string $fileName, int $bunchSize = 100): bool
387377 ['importExportData ' => $ importExportData ]
388378 );
389379 $ filesystem = $ this ->objectManager ->create (Filesystem::class);
390- $ directory = $ filesystem ->getDirectoryWrite (DirectoryList::VAR_IMPORT_EXPORT );
391-
392- $ dirPath = $ directory ->getAbsolutePath ('import ' );
393- $ driver = $ directory ->getDriver ();
394- $ driver ->createDirectory ($ dirPath );
395- $ driver ->filePutContents (
396- $ dirPath . DIRECTORY_SEPARATOR . $ fileName ,
397- file_get_contents (__DIR__ . DIRECTORY_SEPARATOR . '_files ' . DIRECTORY_SEPARATOR . $ fileName )
398- );
380+ $ directory = $ filesystem ->getDirectoryWrite (DirectoryList::ROOT );
399381 $ source = $ this ->objectManager ->create (
400382 Csv::class,
401383 [
402- 'file ' => $ dirPath . DIRECTORY_SEPARATOR . $ fileName ,
384+ 'file ' => __DIR__ . DIRECTORY_SEPARATOR . ' _files ' . DIRECTORY_SEPARATOR . $ fileName ,
403385 'directory ' => $ directory ,
404386 ]
405387 );
388+ $ mediaDirectory = $ filesystem ->getDirectoryWrite (DirectoryList::MEDIA );
389+ $ mediaDirectory ->create ('import ' );
406390 $ errors = $ this ->_model ->setParameters (
407391 [
408392 'behavior ' => Import::BEHAVIOR_APPEND ,
409393 'entity ' => 'catalog_product ' ,
410394 Import::FIELDS_ENCLOSURE => 1 ,
411- Import::FIELD_NAME_IMG_FILE_DIR => $ this ->getMediaDirPath ($ directory ) . '/import '
395+ Import::FIELD_NAME_IMG_FILE_DIR => $ this ->getMediaDirPath ($ mediaDirectory ) . '/import '
412396 ]
413397 )
414398 ->setSource ($ source )
415399 ->validateData ();
416400
417401 $ this ->assertTrue ($ errors ->getErrorsCount () === 0 );
418402
419- $ result = $ this ->_model ->importData ();
420- $ source ->destruct ();
421- return $ result ;
403+ return $ this ->_model ->importData ();
422404 }
423405
424406 /**
0 commit comments