Skip to content

Commit f937ea7

Browse files
committed
B2B-2023: [AWS S3] [Integration Tests]: Investigate Test Failures in CatalogImportExport module
1 parent 8bd3558 commit f937ea7

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

app/code/Magento/ImportExport/Model/Import/Source/Csv.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\ImportExport\Model\Import\Source;
77

8+
use Magento\Framework\Filesystem\Directory\Read;
9+
810
/**
911
* CSV import adapter
1012
*/
@@ -27,26 +29,39 @@ class Csv extends \Magento\ImportExport\Model\Import\AbstractSource
2729
*/
2830
protected $_enclosure = '';
2931

32+
/**
33+
* @var string
34+
*/
35+
private string $filePath;
36+
37+
/**
38+
* @var array
39+
*/
40+
private static array $openFiles;
41+
3042
/**
3143
* Open file and detect column names
3244
*
3345
* There must be column names in the first line
3446
*
3547
* @param string $file
36-
* @param \Magento\Framework\Filesystem\Directory\Read $directory
48+
* @param Read $directory
3749
* @param string $delimiter
3850
* @param string $enclosure
3951
* @throws \LogicException
4052
*/
4153
public function __construct(
4254
$file,
43-
\Magento\Framework\Filesystem\Directory\Read $directory,
55+
Read $directory,
4456
$delimiter = ',',
4557
$enclosure = '"'
4658
) {
4759
register_shutdown_function([$this, 'destruct']);
4860
try {
49-
$this->_file = $directory->openFile($directory->getRelativePath($file), 'r');
61+
$this->filePath = $directory->getRelativePath($file);
62+
$this->_file = $directory->openFile($this->filePath, 'r');
63+
$this->_file->seek(0);
64+
self::$openFiles[$this->filePath] = true;
5065
} catch (\Magento\Framework\Exception\FileSystemException $e) {
5166
throw new \LogicException("Unable to open file: '{$file}'");
5267
}
@@ -64,8 +79,9 @@ public function __construct(
6479
*/
6580
public function destruct()
6681
{
67-
if (is_object($this->_file)) {
82+
if (is_object($this->_file) && !empty(self::$openFiles[$this->filePath])) {
6883
$this->_file->close();
84+
unset(self::$openFiles[$this->filePath]);
6985
}
7086
}
7187

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/AbstractProductExportImportTestCase.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,16 @@ private function exportProducts(Product $exportProduct = null)
412412
$exportProduct = $exportProduct ?: $this->objectManager->create(
413413
Product::class
414414
);
415-
$directory = $this->fileSystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
416-
$directory->touch($csvfile);
417415
$writer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
418416
\Magento\ImportExport\Model\Export\Adapter\Csv::class,
419-
['fileSystem' => $this->fileSystem, 'destination' => $csvfile]
417+
['fileSystem' => $this->fileSystem]
420418
);
421419
$exportProduct->setWriter($writer);
422-
$this->assertNotEmpty($exportProduct->export());
420+
$content = $exportProduct->export();
421+
$this->assertNotEmpty($content);
422+
423+
$directory = $this->fileSystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
424+
$directory->getDriver()->filePutContents($directory->getAbsolutePath($csvfile), $content);
423425

424426
return $csvfile;
425427
}

0 commit comments

Comments
 (0)