7
7
8
8
namespace Magento \CatalogImportExport \Model \Import ;
9
9
10
+ use Magento \Catalog \Api \Data \ProductAttributeInterface ;
11
+ use Magento \Catalog \Api \Data \ProductInterface ;
10
12
use Magento \Catalog \Api \ProductRepositoryInterface ;
11
13
use Magento \Catalog \Model \Product ;
12
14
use Magento \CatalogImportExport \Model \Import \Product \RowValidatorInterface ;
13
15
use Magento \CatalogImportExport \Model \Import \ProductImport ;
14
16
use Magento \Framework \App \Filesystem \DirectoryList ;
15
- use Magento \Framework \File \Csv ;
16
17
use Magento \Framework \Filesystem ;
17
18
use Magento \Framework \Filesystem \Directory \Write ;
18
- use Magento \Framework \MessageQueue \MessageEncoder ;
19
+ use Magento \Framework \MessageQueue \ConsumerFactory ;
20
+ use Magento \Framework \MessageQueue \PublisherInterface ;
19
21
use Magento \Framework \ObjectManagerInterface ;
20
- use Magento \ImportExport \Model \Export \Consumer ;
22
+ use Magento \ImportExport \Model \Export \Entity \ExportInfo ;
23
+ use Magento \ImportExport \Model \Export \Entity \ExportInfoFactory ;
21
24
use Magento \ImportExport \Model \Import as ImportModel ;
22
25
use Magento \ImportExport \Model \Import \Source \Csv as CsvSource ;
23
26
use Magento \ImportExport \Model \Import \Source \CsvFactory ;
24
- use Magento \MysqlMq \Model \Driver \Queue ;
25
27
use Magento \TestFramework \Helper \Bootstrap ;
26
28
use Magento \TestFramework \MysqlMq \DeleteTopicRelatedMessages ;
27
29
use PHPUnit \Framework \TestCase ;
@@ -42,17 +44,8 @@ class ImportWithNotExistImagesTest extends TestCase
42
44
/** @var ObjectManagerInterface */
43
45
private $ objectManager ;
44
46
45
- /** @var MessageEncoder */
46
- private $ messageEncoder ;
47
-
48
- /** @var Consumer */
49
- private $ consumer ;
50
-
51
- /** @var Queue */
52
- private $ queue ;
53
-
54
- /** @var Csv */
55
- private $ csvReader ;
47
+ /** @var ConsumerFactory */
48
+ private $ consumerFactory ;
56
49
57
50
/** @var Write */
58
51
private $ directory ;
@@ -93,10 +86,7 @@ protected function setUp(): void
93
86
parent ::setUp ();
94
87
95
88
$ this ->objectManager = Bootstrap::getObjectManager ();
96
- $ this ->queue = $ this ->objectManager ->create (Queue::class, ['queueName ' => 'export ' ]);
97
- $ this ->messageEncoder = $ this ->objectManager ->get (MessageEncoder::class);
98
- $ this ->consumer = $ this ->objectManager ->get (Consumer::class);
99
- $ this ->csvReader = $ this ->objectManager ->get (Csv::class);
89
+ $ this ->consumerFactory = $ this ->objectManager ->get (ConsumerFactory::class);
100
90
$ this ->import = $ this ->objectManager ->get (ProductFactory::class)->create ();
101
91
$ this ->csvFactory = $ this ->objectManager ->get (CsvFactory::class);
102
92
$ this ->fileSystem = $ this ->objectManager ->get (Filesystem::class);
@@ -118,13 +108,27 @@ protected function tearDown(): void
118
108
}
119
109
120
110
/**
121
- * @magentoDataFixture Magento/CatalogImportExport /_files/export_queue_product_with_images .php
111
+ * @magentoDataFixture Magento/Catalog /_files/product_with_image .php
122
112
*
123
113
* @return void
124
114
*/
125
115
public function testImportWithUnexistingImages (): void
126
116
{
117
+ $ cache = $ this ->objectManager ->get (\Magento \Framework \App \Cache::class);
118
+ $ cache ->clean ();
119
+ /** @var ExportInfoFactory $exportInfoFactory */
120
+ $ exportInfoFactory = $ this ->objectManager ->get (ExportInfoFactory::class);
121
+ $ messagePublisher = $ this ->objectManager ->get (PublisherInterface::class);
122
+ /** @var ExportInfo $dataObject */
123
+ $ dataObject = $ exportInfoFactory ->create (
124
+ 'csv ' ,
125
+ ProductAttributeInterface::ENTITY_TYPE_CODE ,
126
+ [ProductInterface::SKU => 'simple ' ],
127
+ []
128
+ );
129
+ $ messagePublisher ->publish (self ::TOPIC , $ dataObject );
127
130
$ this ->exportProducts ();
131
+ $ this ->filePath = 'export/ ' . $ dataObject ->getFileName ();
128
132
$ this ->assertTrue ($ this ->directory ->isExist ($ this ->filePath ), 'Products were not imported to file ' );
129
133
$ fileContent = $ this ->getCsvData ($ this ->directory ->getAbsolutePath ($ this ->filePath ));
130
134
$ this ->assertCount (2 , $ fileContent );
@@ -147,10 +151,8 @@ public function testImportWithUnexistingImages(): void
147
151
*/
148
152
private function exportProducts (): void
149
153
{
150
- $ envelope = $ this ->queue ->dequeue ();
151
- $ decodedMessage = $ this ->messageEncoder ->decode (self ::TOPIC , $ envelope ->getBody ());
152
- $ this ->consumer ->process ($ decodedMessage );
153
- $ this ->filePath = 'export/ ' . $ decodedMessage ->getFileName ();
154
+ $ consumer = $ this ->consumerFactory ->get ('exportProcessor ' );
155
+ $ consumer ->process (1 );
154
156
}
155
157
156
158
/**
0 commit comments