RecurringTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\MysqlMq\Test\Unit\Setup;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  8. /**
  9. * Class RecurringTest
  10. */
  11. class RecurringTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var ObjectManager
  15. */
  16. private $objectManager;
  17. /**
  18. * @var \Magento\MysqlMq\Setup\Recurring
  19. */
  20. private $model;
  21. /**
  22. * @var \Magento\Framework\MessageQueue\ConfigInterface|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. private $messageQueueConfig;
  25. /**
  26. * {@inheritdoc}
  27. */
  28. protected function setUp()
  29. {
  30. $this->objectManager = new ObjectManager($this);
  31. $this->messageQueueConfig = $this->getMockBuilder(\Magento\Framework\MessageQueue\ConfigInterface::class)
  32. ->getMockForAbstractClass();
  33. $this->model = $this->objectManager->getObject(
  34. \Magento\MysqlMq\Setup\Recurring::class,
  35. [
  36. 'messageQueueConfig' => $this->messageQueueConfig,
  37. ]
  38. );
  39. }
  40. /**
  41. * Test for install method
  42. */
  43. public function testInstall()
  44. {
  45. $binds = [
  46. 'first_bind' => [
  47. 'queue' => 'queue_name_1',
  48. 'exchange' => 'magento-db',
  49. 'topic' => 'queue.topic.1'
  50. ],
  51. 'second_bind' => [
  52. 'queue' => 'queue_name_2',
  53. 'exchange' => 'magento-db',
  54. 'topic' => 'queue.topic.2'
  55. ],
  56. 'third_bind' => [
  57. 'queue' => 'queue_name_3',
  58. 'exchange' => 'magento-db',
  59. 'topic' => 'queue.topic.3'
  60. ]
  61. ];
  62. $dbQueues = [
  63. 'queue_name_1',
  64. 'queue_name_2',
  65. ];
  66. $queuesToInsert = [
  67. 2 => 'queue_name_3'
  68. ];
  69. $queueTableName = 'queue_table';
  70. $setup = $this->getMockBuilder(\Magento\Framework\Setup\SchemaSetupInterface::class)
  71. ->getMockForAbstractClass();
  72. $context = $this->getMockBuilder(\Magento\Framework\Setup\ModuleContextInterface::class)
  73. ->getMockForAbstractClass();
  74. $setup->expects($this->once())->method('startSetup')->willReturnSelf();
  75. $this->messageQueueConfig->expects($this->once())->method('getBinds')->willReturn($binds);
  76. $connection = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)
  77. ->getMockForAbstractClass();
  78. $setup->expects($this->once())->method('getConnection')->willReturn($connection);
  79. $setup->expects($this->any())->method('getTable')->with('queue')->willReturn($queueTableName);
  80. $select = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
  81. ->disableOriginalConstructor()
  82. ->getMock();
  83. $connection->expects($this->once())->method('select')->willReturn($select);
  84. $select->expects($this->once())->method('from')->with($queueTableName, 'name')->willReturnSelf();
  85. $connection->expects($this->once())->method('fetchCol')->with($select)->willReturn($dbQueues);
  86. $connection->expects($this->once())->method('insertArray')->with($queueTableName, ['name'], $queuesToInsert);
  87. $setup->expects($this->once())->method('endSetup')->willReturnSelf();
  88. $this->model->install($setup, $context);
  89. }
  90. }