9
9
10
10
use Magento \Catalog \Api \Data \ProductInterface ;
11
11
use Magento \Framework \App \Filesystem \DirectoryList ;
12
- use Magento \Framework \File \Csv ;
13
12
use Magento \Framework \Filesystem ;
14
- use Magento \Framework \Filesystem \Directory \Write ;
13
+ use Magento \Framework \Filesystem \Directory \WriteInterface ;
15
14
use Magento \Framework \MessageQueue \MessageEncoder ;
16
15
use Magento \Framework \ObjectManagerInterface ;
17
16
use Magento \MysqlMq \Model \Driver \Queue ;
@@ -40,10 +39,7 @@ class ConsumerTest extends TestCase
40
39
/** @var Queue */
41
40
private $ queue ;
42
41
43
- /** @var Csv */
44
- private $ csvReader ;
45
-
46
- /** @var Write */
42
+ /** @var WriteInterface */
47
43
private $ directory ;
48
44
49
45
/** @var string */
@@ -60,8 +56,8 @@ protected function setUp(): void
60
56
$ this ->queue = $ this ->objectManager ->create (Queue::class, ['queueName ' => 'export ' ]);
61
57
$ this ->messageEncoder = $ this ->objectManager ->get (MessageEncoder::class);
62
58
$ 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 );
65
61
}
66
62
67
63
/**
@@ -91,7 +87,7 @@ public function testProcess(): void
91
87
$ this ->consumer ->process ($ decodedMessage );
92
88
$ this ->filePath = 'export/ ' . $ decodedMessage ->getFileName ();
93
89
$ 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 ));
95
91
$ this ->assertCount (2 , $ data );
96
92
$ skuPosition = $ this ->getSkuPosition ($ data );
97
93
$ this ->assertNotNull ($ skuPosition );
@@ -117,4 +113,25 @@ private function getSkuPosition(array $csvFileData): ?int
117
113
118
114
return null ;
119
115
}
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
+ }
120
137
}
0 commit comments