9
9
use Magento \Framework \App \Bootstrap ;
10
10
use Magento \Framework \App \Filesystem \DirectoryList ;
11
11
use Magento \ImportExport \Model \Export \Adapter \AbstractAdapter ;
12
+ use Magento \Framework \Filesystem \Driver \File ;
12
13
use Magento \Store \Model \Store ;
13
14
use Magento \TestFramework \Annotation \DataFixture ;
14
15
use Magento \TestFramework \Workaround \Override \Fixture \Resolver ;
@@ -66,11 +67,6 @@ abstract class AbstractProductExportImportTestCase extends \PHPUnit\Framework\Te
66
67
'tax_class_id ' ,
67
68
];
68
69
69
- /**
70
- * @var AbstractAdapter
71
- */
72
- private $ writer ;
73
-
74
70
/**
75
71
* @var string
76
72
*/
@@ -97,7 +93,7 @@ protected function tearDown(): void
97
93
$ this ->executeFixtures ($ this ->fixtures , true );
98
94
99
95
if ($ this ->csvFile !== null ) {
100
- $ directoryWrite = $ this ->fileSystem ->getDirectoryWrite (DirectoryList::VAR_DIR );
96
+ $ directoryWrite = $ this ->fileSystem ->getDirectoryWrite (DirectoryList::VAR_IMPORT_EXPORT );
101
97
$ directoryWrite ->delete ($ this ->csvFile );
102
98
}
103
99
}
@@ -416,12 +412,13 @@ private function exportProducts(Product $exportProduct = null)
416
412
$ exportProduct = $ exportProduct ?: $ this ->objectManager ->create (
417
413
Product::class
418
414
);
419
- $ this -> writer = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
415
+ $ writer = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
420
416
\Magento \ImportExport \Model \Export \Adapter \Csv::class,
421
417
['fileSystem ' => $ this ->fileSystem , 'destination ' => $ csvfile ]
422
418
);
423
- $ exportProduct ->setWriter ($ this -> writer );
419
+ $ exportProduct ->setWriter ($ writer );
424
420
$ this ->assertNotEmpty ($ exportProduct ->export ());
421
+ $ writer ->getFileHandler ()->close ();
425
422
426
423
return $ csvfile ;
427
424
}
@@ -451,19 +448,21 @@ private function importProducts(string $csvfile, string $behavior): void
451
448
$ appParams = \Magento \TestFramework \Helper \Bootstrap::getInstance ()->getBootstrap ()
452
449
->getApplication ()
453
450
->getInitParams ()[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS ];
454
- $ uploader = $ importModel ->getUploader ();
455
- $ rootDirectory = $ this ->fileSystem ->getDirectoryWrite (DirectoryList::ROOT );
456
- $ destDir = $ rootDirectory ->getRelativePath (
457
- $ appParams [DirectoryList::MEDIA ][DirectoryList::PATH ] . '/catalog/product '
458
- );
459
- $ tmpDir = $ rootDirectory ->getRelativePath (
460
- $ appParams [DirectoryList::MEDIA ][DirectoryList::PATH ] . '/import '
461
- );
451
+ $ mediaDirectory = $ this ->fileSystem ->getDirectoryWrite (DirectoryList::MEDIA );
462
452
463
- $ rootDirectory ->create ($ destDir );
464
- $ rootDirectory ->create ($ tmpDir );
465
- $ this ->assertTrue ($ uploader ->setDestDir ($ destDir ));
466
- $ this ->assertTrue ($ uploader ->setTmpDir ($ tmpDir ));
453
+ $ mediaDir = $ mediaDirectory ->getDriver () instanceof File ?
454
+ $ appParams [DirectoryList::MEDIA ][DirectoryList::PATH ] : 'media ' ;
455
+
456
+ $ mediaDirectory ->create ('catalog/product ' );
457
+ $ mediaDirectory ->create ('import ' );
458
+ $ importModel ->setParameters (
459
+ [
460
+ \Magento \ImportExport \Model \Import::FIELD_NAME_IMG_FILE_DIR => $ mediaDir . '/import '
461
+ ]
462
+ );
463
+ $ uploader = $ importModel ->getUploader ();
464
+ $ this ->assertTrue ($ uploader ->setDestDir ($ mediaDir . '/catalog/product ' ));
465
+ $ this ->assertTrue ($ uploader ->setTmpDir ($ mediaDir . '/import ' ));
467
466
468
467
$ errors = $ importModel ->setParameters (
469
468
[
0 commit comments