Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RecurringTest.php
Go to the documentation of this file.
1 <?php
8 
10 
14 class RecurringTest extends \PHPUnit\Framework\TestCase
15 {
19  private $objectManager;
20 
24  private $model;
25 
29  private $messageQueueConfig;
30 
34  protected function setUp()
35  {
36  $this->objectManager = new ObjectManager($this);
37  $this->messageQueueConfig = $this->getMockBuilder(\Magento\Framework\MessageQueue\ConfigInterface::class)
38  ->getMockForAbstractClass();
39  $this->model = $this->objectManager->getObject(
40  \Magento\MysqlMq\Setup\Recurring::class,
41  [
42  'messageQueueConfig' => $this->messageQueueConfig,
43  ]
44  );
45  }
46 
50  public function testInstall()
51  {
52  $binds = [
53  'first_bind' => [
54  'queue' => 'queue_name_1',
55  'exchange' => 'magento-db',
56  'topic' => 'queue.topic.1'
57  ],
58  'second_bind' => [
59  'queue' => 'queue_name_2',
60  'exchange' => 'magento-db',
61  'topic' => 'queue.topic.2'
62  ],
63  'third_bind' => [
64  'queue' => 'queue_name_3',
65  'exchange' => 'magento-db',
66  'topic' => 'queue.topic.3'
67  ]
68  ];
69  $dbQueues = [
70  'queue_name_1',
71  'queue_name_2',
72  ];
73  $queuesToInsert = [
74  2 => 'queue_name_3'
75  ];
76  $queueTableName = 'queue_table';
77 
78  $setup = $this->getMockBuilder(\Magento\Framework\Setup\SchemaSetupInterface::class)
79  ->getMockForAbstractClass();
80  $context = $this->getMockBuilder(\Magento\Framework\Setup\ModuleContextInterface::class)
81  ->getMockForAbstractClass();
82 
83  $setup->expects($this->once())->method('startSetup')->willReturnSelf();
84  $this->messageQueueConfig->expects($this->once())->method('getBinds')->willReturn($binds);
85  $connection = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)
86  ->getMockForAbstractClass();
87  $setup->expects($this->once())->method('getConnection')->willReturn($connection);
88  $setup->expects($this->any())->method('getTable')->with('queue')->willReturn($queueTableName);
89  $select = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
90  ->disableOriginalConstructor()
91  ->getMock();
92  $connection->expects($this->once())->method('select')->willReturn($select);
93  $select->expects($this->once())->method('from')->with($queueTableName, 'name')->willReturnSelf();
94  $connection->expects($this->once())->method('fetchCol')->with($select)->willReturn($dbQueues);
95  $connection->expects($this->once())->method('insertArray')->with($queueTableName, ['name'], $queuesToInsert);
96  $setup->expects($this->once())->method('endSetup')->willReturnSelf();
97 
98  $this->model->install($setup, $context);
99  }
100 }
$setup
Definition: trigger.php:12
$connection
Definition: bulk.php:13