77
88namespace Magento \ImportExport \Model \Export ;
99
10+ use Magento \Catalog \Api \Data \ProductAttributeInterface ;
1011use Magento \Catalog \Api \Data \ProductInterface ;
1112use Magento \Framework \App \Filesystem \DirectoryList ;
1213use Magento \Framework \Filesystem ;
1314use Magento \Framework \Filesystem \Directory \WriteInterface ;
15+ use Magento \Framework \MessageQueue \ConsumerFactory ;
1416use Magento \Framework \MessageQueue \DefaultValueProvider ;
1517use Magento \Framework \MessageQueue \MessageEncoder ;
18+ use Magento \Framework \MessageQueue \PublisherInterface ;
1619use Magento \Framework \MessageQueue \QueueRepository ;
1720use Magento \Framework \ObjectManagerInterface ;
21+ use Magento \ImportExport \Model \Export \Entity \ExportInfoFactory ;
1822use Magento \TestFramework \Helper \Bootstrap ;
1923use PHPUnit \Framework \TestCase ;
2024
@@ -53,6 +57,9 @@ class ConsumerTest extends TestCase
5357 */
5458 private $ defaultValueProvider ;
5559
60+ /** @var ConsumerFactory */
61+ private $ consumerFactory ;
62+
5663 /**
5764 * @inheritdoc
5865 */
@@ -67,6 +74,7 @@ protected function setUp(): void
6774 $ this ->directory = $ filesystem ->getDirectoryWrite (DirectoryList::VAR_IMPORT_EXPORT );
6875 $ this ->queueRepository = $ this ->objectManager ->get (QueueRepository::class);
6976 $ this ->defaultValueProvider = $ this ->objectManager ->get (DefaultValueProvider::class);
77+ $ this ->consumerFactory = $ this ->objectManager ->get (ConsumerFactory::class);
7078 }
7179
7280 /**
@@ -84,18 +92,28 @@ protected function tearDown(): void
8492 /**
8593 * @magentoConfigFixture default_store admin/security/use_form_key 1
8694 *
87- * @magentoDataFixture Magento/ImportExport /_files/export_queue_data .php
95+ * @magentoDataFixture Magento/Catalog /_files/second_product_simple .php
8896 * @magentoDataFixture Magento/Catalog/_files/product_virtual.php
8997 *
9098 * @return void
9199 */
92100 public function testProcess (): void
93101 {
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 ();
99117 $ this ->assertTrue ($ this ->directory ->isExist ($ this ->filePath ));
100118 $ data = $ this ->getCsvData ($ this ->directory ->getAbsolutePath ($ this ->filePath ));
101119 $ this ->assertCount (2 , $ data );
0 commit comments