99
1010use Magento \Catalog \Api \Data \ProductInterface ;
1111use Magento \Framework \App \Filesystem \DirectoryList ;
12- use Magento \Framework \File \Csv ;
1312use Magento \Framework \Filesystem ;
14- use Magento \Framework \Filesystem \Directory \Write ;
13+ use Magento \Framework \Filesystem \Directory \WriteInterface ;
1514use Magento \Framework \MessageQueue \MessageEncoder ;
1615use Magento \Framework \ObjectManagerInterface ;
1716use 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}
0 commit comments