7
7
8
8
namespace Magento \ImportExport \Model \Export ;
9
9
10
+ use Magento \Catalog \Api \Data \ProductAttributeInterface ;
10
11
use Magento \Catalog \Api \Data \ProductInterface ;
11
12
use Magento \Framework \App \Filesystem \DirectoryList ;
12
13
use Magento \Framework \Filesystem ;
13
14
use Magento \Framework \Filesystem \Directory \WriteInterface ;
15
+ use Magento \Framework \MessageQueue \ConsumerFactory ;
14
16
use Magento \Framework \MessageQueue \DefaultValueProvider ;
15
17
use Magento \Framework \MessageQueue \MessageEncoder ;
18
+ use Magento \Framework \MessageQueue \PublisherInterface ;
16
19
use Magento \Framework \MessageQueue \QueueRepository ;
17
20
use Magento \Framework \ObjectManagerInterface ;
21
+ use Magento \ImportExport \Model \Export \Entity \ExportInfoFactory ;
18
22
use Magento \TestFramework \Helper \Bootstrap ;
19
23
use PHPUnit \Framework \TestCase ;
20
24
@@ -53,6 +57,9 @@ class ConsumerTest extends TestCase
53
57
*/
54
58
private $ defaultValueProvider ;
55
59
60
+ /** @var ConsumerFactory */
61
+ private $ consumerFactory ;
62
+
56
63
/**
57
64
* @inheritdoc
58
65
*/
@@ -67,6 +74,7 @@ protected function setUp(): void
67
74
$ this ->directory = $ filesystem ->getDirectoryWrite (DirectoryList::VAR_IMPORT_EXPORT );
68
75
$ this ->queueRepository = $ this ->objectManager ->get (QueueRepository::class);
69
76
$ this ->defaultValueProvider = $ this ->objectManager ->get (DefaultValueProvider::class);
77
+ $ this ->consumerFactory = $ this ->objectManager ->get (ConsumerFactory::class);
70
78
}
71
79
72
80
/**
@@ -84,18 +92,28 @@ protected function tearDown(): void
84
92
/**
85
93
* @magentoConfigFixture default_store admin/security/use_form_key 1
86
94
*
87
- * @magentoDataFixture Magento/ImportExport /_files/export_queue_data .php
95
+ * @magentoDataFixture Magento/Catalog /_files/second_product_simple .php
88
96
* @magentoDataFixture Magento/Catalog/_files/product_virtual.php
89
97
*
90
98
* @return void
91
99
*/
92
100
public function testProcess (): void
93
101
{
94
- $ queue = $ this ->queueRepository ->get ($ this ->defaultValueProvider ->getConnection (), 'export ' );
95
- $ envelope = $ queue ->dequeue ();
96
- $ decodedMessage = $ this ->messageEncoder ->decode ('import_export.export ' , $ envelope ->getBody ());
97
- $ this ->consumer ->process ($ decodedMessage );
98
- $ this ->filePath = 'export/ ' . $ decodedMessage ->getFileName ();
102
+ $ objectManager = Bootstrap::getObjectManager ();
103
+ /** @var ExportInfoFactory $exportInfoFactory */
104
+ $ exportInfoFactory = $ objectManager ->get (ExportInfoFactory::class);
105
+ /** @var PublisherInterface $messagePublisher */
106
+ $ messagePublisher = $ objectManager ->get (PublisherInterface::class);
107
+ $ dataObject = $ exportInfoFactory ->create (
108
+ 'csv ' ,
109
+ ProductAttributeInterface::ENTITY_TYPE_CODE ,
110
+ [ProductInterface::SKU => 'simple2 ' ],
111
+ []
112
+ );
113
+ $ messagePublisher ->publish ('import_export.export ' , $ dataObject );
114
+ $ consumer = $ this ->consumerFactory ->get ('exportProcessor ' );
115
+ $ consumer ->process (1 );
116
+ $ this ->filePath = 'export/ ' . $ dataObject ->getFileName ();
99
117
$ this ->assertTrue ($ this ->directory ->isExist ($ this ->filePath ));
100
118
$ data = $ this ->getCsvData ($ this ->directory ->getAbsolutePath ($ this ->filePath ));
101
119
$ this ->assertCount (2 , $ data );
0 commit comments