Skip to content

Commit 3618951

Browse files
committed
Merge remote-tracking branch 'arcticfoxes/B2B-2017' into 2.4-develop-pr
2 parents b21f60c + d49170e commit 3618951

File tree

5 files changed

+40
-16
lines changed

5 files changed

+40
-16
lines changed

app/code/Magento/RemoteStorage/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<argument name="writeFactory" xsi:type="object">
2727
Magento\RemoteStorage\Model\Filesystem\Directory\WriteFactory
2828
</argument>
29+
<argument name="readFactory" xsi:type="object">remoteReadFactory</argument>
2930
</arguments>
3031
</type>
3132
<virtualType name="customRemoteFilesystem" type="Magento\RemoteStorage\Filesystem">

dev/tests/integration/testsuite/Magento/ImportExport/Controller/Adminhtml/Export/File/DeleteTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected function setUp(): void
5151
$this->fileSystem = $this->_objectManager->get(Filesystem::class);
5252
$this->sourceFilePath = __DIR__ . '/../../Import/_files' . DIRECTORY_SEPARATOR . $this->fileName;
5353
//Refers to tests 'var' directory
54-
$this->varDirectory = $this->fileSystem->getDirectoryRead(DirectoryList::VAR_IMPORT_EXPORT);
54+
$this->varDirectory = $this->fileSystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
5555
}
5656

5757
/**
@@ -84,12 +84,15 @@ public function testExecute($file): void
8484
*
8585
* @param $destinationFilePath
8686
* @return void
87+
* @throws \Magento\Framework\Exception\FileSystemException
8788
*/
8889
protected function copyFile($destinationFilePath): void
8990
{
90-
//Refers to application root directory
91-
$rootDirectory = $this->fileSystem->getDirectoryWrite(DirectoryList::ROOT);
92-
$rootDirectory->copyFile($this->sourceFilePath, $this->varDirectory->getAbsolutePath($destinationFilePath));
91+
$driver = $this->varDirectory->getDriver();
92+
$absolutePath = $this->varDirectory->getAbsolutePath($destinationFilePath);
93+
94+
$driver->createDirectory(dirname($absolutePath));
95+
$driver->filePutContents($absolutePath, file_get_contents($this->sourceFilePath));
9396
}
9497

9598
/**
@@ -112,7 +115,7 @@ public static function tearDownAfterClass(): void
112115
{
113116
$filesystem = Bootstrap::getObjectManager()->get(Filesystem::class);
114117
/** @var WriteInterface $directory */
115-
$directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
118+
$directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
116119
if ($directory->isExist('export')) {
117120
$directory->delete('export');
118121
}

dev/tests/integration/testsuite/Magento/ImportExport/Model/Export/Adapter/CsvTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ protected function setUp(): void
4848
*/
4949
public function testDestruct(string $destination, bool $shouldBeDeleted): void
5050
{
51-
$csv = $this->objectManager->create(Csv::class, ['destination' => $destination]);
51+
$csv = $this->objectManager->create(Csv::class, [
52+
'destination' => $destination,
53+
'destinationDirectoryCode' => DirectoryList::VAR_DIR
54+
]);
5255
/** @var Filesystem $fileSystem */
5356
$fileSystem = $this->objectManager->get(Filesystem::class);
5457
$directoryHandle = $fileSystem->getDirectoryRead(DirectoryList::VAR_DIR);

dev/tests/integration/testsuite/Magento/ImportExport/Model/Export/ConsumerTest.php

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99

1010
use Magento\Catalog\Api\Data\ProductInterface;
1111
use Magento\Framework\App\Filesystem\DirectoryList;
12-
use Magento\Framework\File\Csv;
1312
use Magento\Framework\Filesystem;
14-
use Magento\Framework\Filesystem\Directory\Write;
13+
use Magento\Framework\Filesystem\Directory\WriteInterface;
1514
use Magento\Framework\MessageQueue\MessageEncoder;
1615
use Magento\Framework\ObjectManagerInterface;
1716
use Magento\MysqlMq\Model\Driver\Queue;
@@ -40,10 +39,7 @@ class ConsumerTest extends TestCase
4039
/** @var Queue */
4140
private $queue;
4241

43-
/** @var Csv */
44-
private $csvReader;
45-
46-
/** @var Write */
42+
/** @var WriteInterface */
4743
private $directory;
4844

4945
/** @var string */
@@ -60,8 +56,8 @@ protected function setUp(): void
6056
$this->queue = $this->objectManager->create(Queue::class, ['queueName' => 'export']);
6157
$this->messageEncoder = $this->objectManager->get(MessageEncoder::class);
6258
$this->consumer = $this->objectManager->get(Consumer::class);
63-
$this->directory = $this->objectManager->get(Filesystem::class)->getDirectoryWrite(DirectoryList::VAR_DIR);
64-
$this->csvReader = $this->objectManager->get(Csv::class);
59+
$filesystem = $this->objectManager->get(Filesystem::class);
60+
$this->directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
6561
}
6662

6763
/**
@@ -91,7 +87,7 @@ public function testProcess(): void
9187
$this->consumer->process($decodedMessage);
9288
$this->filePath = 'export/' . $decodedMessage->getFileName();
9389
$this->assertTrue($this->directory->isExist($this->filePath));
94-
$data = $this->csvReader->getData($this->directory->getAbsolutePath($this->filePath));
90+
$data = $this->getCsvData($this->directory->getAbsolutePath($this->filePath));
9591
$this->assertCount(2, $data);
9692
$skuPosition = $this->getSkuPosition($data);
9793
$this->assertNotNull($skuPosition);
@@ -117,4 +113,25 @@ private function getSkuPosition(array $csvFileData): ?int
117113

118114
return null;
119115
}
116+
117+
/**
118+
* Parse csv file and return csv data as array
119+
*
120+
* @param string $filePath
121+
* @return array
122+
* @throws \Magento\Framework\Exception\FileSystemException
123+
*/
124+
private function getCsvData(string $filePath): array
125+
{
126+
$driver = $this->directory->getDriver();
127+
$fileResource = $driver->fileOpen($filePath, null);
128+
129+
$data = [];
130+
while ($rowData = $driver->fileGetCsv($fileResource, 100000)) {
131+
$data[] = $rowData;
132+
}
133+
$driver->fileClose($fileResource);
134+
135+
return $data;
136+
}
120137
}

dev/tests/integration/testsuite/Magento/ImportExport/Model/Report/CsvTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class CsvTest extends \PHPUnit\Framework\TestCase
4747
protected function setUp(): void
4848
{
4949
$filesystem = Bootstrap::getObjectManager()->create(Filesystem::class);
50-
$this->directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
50+
$this->directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
5151

5252
$this->csvReport = Bootstrap::getObjectManager()->create(Csv::class);
5353
}

0 commit comments

Comments
 (0)