Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataMapperTest.php
Go to the documentation of this file.
1 <?php
7 
9 use Magento\Framework\Communication\ConfigInterface as CommunicationConfig;
12 
13 class DataMapperTest extends \PHPUnit\Framework\TestCase
14 {
18  private $configData;
19 
23  private $communicationConfig;
24 
28  private $queueNameBuilder;
29 
33  private $model;
34 
35  protected function setUp()
36  {
37  $this->configData = $this->createMock(Data::class);
38  $this->communicationConfig = $this->createMock(CommunicationConfig::class);
39  $this->queueNameBuilder = $this->createMock(ResponseQueueNameBuilder::class);
40  $this->model = new DataMapper($this->configData, $this->communicationConfig, $this->queueNameBuilder);
41  }
42 
43  public function testGetMappedData()
44  {
45  $data = [
46  'ex01' => [
47  'name' => 'ex01',
48  'type' => 'topic',
49  'connection' => 'amqp',
50  'durable' => true,
51  'internal' => false,
52  'autoDelete' => false,
53  'arguments' => ['some' => 'argument'],
54  'bindings' => [
55  'bind01' => [
56  'id' => 'bind01',
57  'topic' => 'topic01',
58  'destinationType' => 'queue',
59  'destination' => 'some.queue',
60  'disabled' => false,
61  'arguments' => ['some' => 'arguments'],
62  ],
63  'bind02' => [
64  'id' => 'bind02',
65  'topic' => 'topic02',
66  'destinationType' => 'queue',
67  'destination' => 'some.queue',
68  'disabled' => false,
69  'arguments' => ['some' => 'arguments'],
70  ],
71  ],
72  ],
73  'ex02' => [
74  'name' => 'ex02',
75  'type' => 'exchange',
76  'connection' => 'amqp',
77  'durable' => true,
78  'internal' => false,
79  'autoDelete' => false,
80  'arguments' => ['some' => 'argument'],
81  'bindings' => [
82  'bind01' => [
83  'id' => 'bind01',
84  'topic' => 'topic01',
85  'destinationType' => 'exchange',
86  'destination' => 'some.exchange',
87  'disabled' => false,
88  'arguments' => ['some' => 'arguments'],
89  ],
90  ],
91  ],
92  ];
93 
94  $communicationMap = [
95  ['topic01', ['name' => 'topic01', 'is_synchronous' => true]],
96  ['topic02', ['name' => 'topic02', 'is_synchronous' => false]],
97  ];
98 
99  $this->communicationConfig->expects($this->exactly(2))->method('getTopic')->willReturnMap($communicationMap);
100  $this->configData->expects($this->once())->method('get')->willReturn($data);
101  $this->queueNameBuilder->expects($this->once())
102  ->method('getQueueName')
103  ->with('topic01')
104  ->willReturn('responseQueue.topic01');
105 
106  $actualResult = $this->model->getMappedData();
107  $expectedResult = [
108  'responseQueue.topic01--amqp' => [
109  'name' => 'responseQueue.topic01',
110  'connection' => 'amqp',
111  'durable' => true,
112  'autoDelete' => false,
113  'arguments' => [],
114  ],
115  'some.queue--amqp' => [
116  'name' => 'some.queue',
117  'connection' => 'amqp',
118  'durable' => true,
119  'autoDelete' => false,
120  'arguments' => [],
121  ],
122  ];
123  $this->assertEquals($expectedResult, $actualResult);
124  }
125 
130  {
131  $data = [
132  'ex01' => [
133  'name' => 'ex01',
134  'type' => 'topic',
135  'connection' => 'amqp',
136  'durable' => true,
137  'internal' => false,
138  'autoDelete' => false,
139  'arguments' => ['some' => 'argument'],
140  'bindings' => [
141  'bind01' => [
142  'id' => 'bind01',
143  'topic' => '#',
144  'destinationType' => 'queue',
145  'destination' => 'some.queue',
146  'disabled' => false,
147  'arguments' => ['some' => 'arguments'],
148  ],
149  'bind02' => [
150  'id' => 'bind02',
151  'topic' => '*.*.*',
152  'destinationType' => 'queue',
153  'destination' => 'some.queue',
154  'disabled' => false,
155  'arguments' => ['some' => 'arguments'],
156  ],
157  'bind03' => [
158  'id' => 'bind03',
159  'topic' => 'topic01',
160  'destinationType' => 'queue',
161  'destination' => 'some.queue',
162  'disabled' => false,
163  'arguments' => ['some' => 'arguments'],
164  ],
165  ],
166  ],
167  'ex02' => [
168  'name' => 'ex02',
169  'type' => 'topic',
170  'connection' => 'amqp',
171  'durable' => true,
172  'internal' => false,
173  'autoDelete' => false,
174  'arguments' => ['some' => 'argument'],
175  'bindings' => [
176  'bind01' => [
177  'id' => 'bind01',
178  'topic' => '#.some.*',
179  'destinationType' => 'queue',
180  'destination' => 'some.queue',
181  'disabled' => false,
182  'arguments' => ['some' => 'arguments'],
183  ],
184  ],
185  ],
186  ];
187 
188  $communicationData = [
189  'topic01' => ['name' => 'topic01', 'is_synchronous' => true],
190  'topic02' => ['name' => 'topic02', 'is_synchronous' => true],
191  'topic03' => ['name' => 'topic03', 'is_synchronous' => true],
192  'topic04.04.04' => ['name' => 'topic04.04.04', 'is_synchronous' => true],
193  'topic05.05' => ['name' => 'topic05.05', 'is_synchronous' => true],
194  'topic06.06.06' => ['name' => 'topic06.06.06', 'is_synchronous' => false],
195  'topic07' => ['name' => 'topic07', 'is_synchronous' => false],
196  'topic08.part2.some.test' => ['name' => 'topic08.part2.some.test', 'is_synchronous' => true],
197  ];
198 
199  $this->communicationConfig->expects($this->once())
200  ->method('getTopic')
201  ->with('topic01')
202  ->willReturn(['name' => 'topic01', 'is_synchronous' => true]);
203  $this->communicationConfig->expects($this->any())->method('getTopics')->willReturn($communicationData);
204  $this->configData->expects($this->once())->method('get')->willReturn($data);
205  $this->queueNameBuilder->expects($this->any())
206  ->method('getQueueName')
207  ->willReturnCallback(function ($value) {
208  return 'responseQueue.' . $value;
209  });
210 
211  $actualResult = $this->model->getMappedData();
212  $expectedResult = [
213  'responseQueue.topic01--amqp' => [
214  'name' => 'responseQueue.topic01',
215  'connection' => 'amqp',
216  'durable' => true,
217  'autoDelete' => false,
218  'arguments' => [],
219  ],
220  'some.queue--amqp' => [
221  'name' => 'some.queue',
222  'connection' => 'amqp',
223  'durable' => true,
224  'autoDelete' => false,
225  'arguments' => [],
226  ],
227  'responseQueue.topic02--amqp' => [
228  'name' => 'responseQueue.topic02',
229  'connection' => 'amqp',
230  'durable' => true,
231  'autoDelete' => false,
232  'arguments' => [],
233  ],
234  'responseQueue.topic03--amqp' => [
235  'name' => 'responseQueue.topic03',
236  'connection' => 'amqp',
237  'durable' => true,
238  'autoDelete' => false,
239  'arguments' => [],
240  ],
241  'responseQueue.topic04.04.04--amqp' => [
242  'name' => 'responseQueue.topic04.04.04',
243  'connection' => 'amqp',
244  'durable' => true,
245  'autoDelete' => false,
246  'arguments' => [],
247  ],
248  'responseQueue.topic05.05--amqp' => [
249  'name' => 'responseQueue.topic05.05',
250  'connection' => 'amqp',
251  'durable' => true,
252  'autoDelete' => false,
253  'arguments' => [],
254  ],
255  'responseQueue.topic08.part2.some.test--amqp' => [
256  'name' => 'responseQueue.topic08.part2.some.test',
257  'connection' => 'amqp',
258  'durable' => true,
259  'autoDelete' => false,
260  'arguments' => [],
261  ]
262  ];
263  $this->assertEquals($expectedResult, $actualResult);
264  }
265 }
$value
Definition: gender.phtml:16