QueueTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\MysqlMq\Model\Driver;
  7. use Magento\MysqlMq\Model\Driver\Queue;
  8. /**
  9. * Test for MySQL queue driver class.
  10. *
  11. * @magentoDbIsolation disabled
  12. */
  13. class QueueTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * @var Queue
  17. */
  18. protected $queue;
  19. /**
  20. * @var \Magento\Framework\ObjectManagerInterface
  21. */
  22. protected $objectManager;
  23. protected function setUp()
  24. {
  25. $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  26. /** @var \Magento\Framework\MessageQueue\Config\Data $queueConfig */
  27. $queueConfig = $this->objectManager->get(\Magento\Framework\MessageQueue\Config\Data::class);
  28. $queueConfig->reset();
  29. $this->queue = $this->objectManager->create(
  30. \Magento\MysqlMq\Model\Driver\Queue::class,
  31. ['queueName' => 'queue2']
  32. );
  33. }
  34. protected function tearDown()
  35. {
  36. /** @var \Magento\Framework\MessageQueue\Config\Data $queueConfig */
  37. $queueConfig = $this->objectManager->get(\Magento\Framework\MessageQueue\Config\Data::class);
  38. $queueConfig->reset();
  39. }
  40. /**
  41. * @magentoDataFixture Magento/MysqlMq/_files/queues.php
  42. */
  43. public function testPushAndDequeue()
  44. {
  45. /** @var \Magento\Framework\MessageQueue\EnvelopeFactory $envelopFactory */
  46. $envelopFactory = $this->objectManager->get(\Magento\Framework\MessageQueue\EnvelopeFactory::class);
  47. $messageBody = '{"data": {"body": "Message body"}, "message_id": 1}';
  48. $topicName = 'some.topic';
  49. $envelop = $envelopFactory->create(['body' => $messageBody, 'properties' => ['topic_name' => $topicName]]);
  50. $this->queue->push($envelop);
  51. $messageFromQueue = $this->queue->dequeue();
  52. $this->assertEquals($messageBody, $messageFromQueue->getBody());
  53. $actualMessageProperties = $messageFromQueue->getProperties();
  54. $this->assertArrayHasKey('topic_name', $actualMessageProperties);
  55. $this->assertEquals($topicName, $actualMessageProperties['topic_name']);
  56. }
  57. }