1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AMQPAL\Adapter\PhpAmqpLib; |
4
|
|
|
|
5
|
|
|
use PhpAmqpLib\Channel\AMQPChannel; |
6
|
|
|
use PhpAmqpLib\Message\AMQPMessage; |
7
|
|
|
use AMQPAL\Adapter\Message; |
8
|
|
|
use AMQPAL\Options; |
9
|
|
|
use Prophecy\Argument; |
10
|
|
|
|
11
|
|
|
class QueueTest extends \PHPUnit_Framework_TestCase |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
public function testSetOptions() |
15
|
|
|
{ |
16
|
|
|
$options = $this->getDefaultOptionsProphet(); |
17
|
|
|
|
18
|
|
|
$queue = new Queue(); |
19
|
|
|
|
20
|
|
|
static::assertSame($queue, $queue->setOptions($options->reveal())); |
|
|
|
|
21
|
|
|
static::assertSame($options->reveal(), $queue->getOptions()); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testSetOptionsWithArray() |
25
|
|
|
{ |
26
|
|
|
$options = ['name' => 'queueName']; |
27
|
|
|
|
28
|
|
|
$queue = new Queue(); |
29
|
|
|
|
30
|
|
|
static::assertSame($queue, $queue->setOptions($options)); |
31
|
|
|
$queueOptions = $queue->getOptions(); |
32
|
|
|
static::assertInstanceOf(Options\QueueOptions::class, $queueOptions); |
33
|
|
|
static::assertEquals('queueName', $queueOptions->getName()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testGetDefaultMessageMapper() |
37
|
|
|
{ |
38
|
|
|
$exchange = new Queue(); |
39
|
|
|
|
40
|
|
|
static::assertInstanceOf(MessageMapper::class, $exchange->getMessageMapper()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testDeclareQueue() |
44
|
|
|
{ |
45
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|AMQPChannel $adapterChannel */ |
46
|
|
|
$adapterChannel = $this->prophesize(AMQPChannel::class); |
47
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|Channel $channel */ |
48
|
|
|
$channel = $this->prophesize(Channel::class); |
49
|
|
|
$options = $this->getDefaultOptionsProphet(); |
50
|
|
|
|
51
|
|
|
$options->isDurable()->willReturn(true); |
|
|
|
|
52
|
|
|
$options->isPassive()->willReturn(true); |
|
|
|
|
53
|
|
|
$options->isAutoDelete()->willReturn(true); |
|
|
|
|
54
|
|
|
$options->isExclusive()->willReturn(true); |
|
|
|
|
55
|
|
|
$options->getName()->willReturn('queueName'); |
|
|
|
|
56
|
|
|
$options->getArguments()->willReturn(['arg1' => 'value1']); |
|
|
|
|
57
|
|
|
$options->isExclusive()->willReturn(true); |
58
|
|
|
|
59
|
|
|
$channel->getResource()->willReturn($adapterChannel); |
|
|
|
|
60
|
|
|
$adapterChannel->queue_declare( |
|
|
|
|
61
|
|
|
'queueName', |
62
|
|
|
true, |
63
|
|
|
true, |
64
|
|
|
true, |
65
|
|
|
true, |
66
|
|
|
false, |
67
|
|
|
['arg1' => 'value1'] |
68
|
|
|
)->shouldBeCalled(); |
69
|
|
|
|
70
|
|
|
$queue = new Queue(); |
71
|
|
|
$queue->setChannel($channel->reveal()); |
|
|
|
|
72
|
|
|
$queue->setOptions($options->reveal()); |
|
|
|
|
73
|
|
|
|
74
|
|
|
static::assertSame($queue, $queue->declareQueue()); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @dataProvider deleteProvider() |
79
|
|
|
*/ |
80
|
|
|
public function testDelete($ifUnused, $ifEmpty, $noWait) |
81
|
|
|
{ |
82
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|AMQPChannel $adapterChannel */ |
83
|
|
|
$adapterChannel = $this->prophesize(AMQPChannel::class); |
84
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|Channel $channel */ |
85
|
|
|
$channel = $this->prophesize(Channel::class); |
86
|
|
|
$options = $this->getDefaultOptionsProphet(); |
87
|
|
|
|
88
|
|
|
$adapterChannel->queue_delete('queueName', $ifUnused, $ifEmpty, $noWait)->shouldBeCalled(); |
|
|
|
|
89
|
|
|
$channel->getResource()->willReturn($adapterChannel->reveal()); |
|
|
|
|
90
|
|
|
|
91
|
|
|
$queue = new Queue(); |
92
|
|
|
$queue->setOptions($options->reveal()); |
|
|
|
|
93
|
|
|
$queue->setChannel($channel->reveal()); |
|
|
|
|
94
|
|
|
|
95
|
|
|
static::assertSame($queue, $queue->delete($ifUnused, $ifEmpty, $noWait)); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testBind() |
99
|
|
|
{ |
100
|
|
|
$arguments = ['arg2' => 'value2']; |
101
|
|
|
|
102
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|AMQPChannel $adapterChannel */ |
103
|
|
|
$adapterChannel = $this->prophesize(AMQPChannel::class); |
104
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|Channel $channel */ |
105
|
|
|
$channel = $this->prophesize(Channel::class); |
106
|
|
|
$options = $this->getDefaultOptionsProphet(); |
107
|
|
|
|
108
|
|
|
$adapterChannel->queue_bind('queueName', 'exchangeName', 'routingKey', false, $arguments)->shouldBeCalled(); |
|
|
|
|
109
|
|
|
$channel->getResource()->willReturn($adapterChannel->reveal()); |
|
|
|
|
110
|
|
|
|
111
|
|
|
$queue = new Queue(); |
112
|
|
|
$queue->setOptions($options->reveal()); |
|
|
|
|
113
|
|
|
$queue->setChannel($channel->reveal()); |
|
|
|
|
114
|
|
|
|
115
|
|
|
static::assertSame($queue, $queue->bind('exchangeName', 'routingKey', false, $arguments)); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function testBindNoWaitAndNullRoutingKey() |
119
|
|
|
{ |
120
|
|
|
$arguments = ['arg2' => 'value2']; |
121
|
|
|
|
122
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|AMQPChannel $adapterChannel */ |
123
|
|
|
$adapterChannel = $this->prophesize(AMQPChannel::class); |
124
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|Channel $channel */ |
125
|
|
|
$channel = $this->prophesize(Channel::class); |
126
|
|
|
$options = $this->getDefaultOptionsProphet(); |
127
|
|
|
|
128
|
|
|
$adapterChannel->queue_bind('queueName', 'exchangeName', '', true, $arguments)->shouldBeCalled(); |
|
|
|
|
129
|
|
|
$channel->getResource()->willReturn($adapterChannel->reveal()); |
|
|
|
|
130
|
|
|
|
131
|
|
|
$queue = new Queue(); |
132
|
|
|
$queue->setOptions($options->reveal()); |
|
|
|
|
133
|
|
|
$queue->setChannel($channel->reveal()); |
|
|
|
|
134
|
|
|
|
135
|
|
|
static::assertSame($queue, $queue->bind('exchangeName', null, true, $arguments)); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function testUnbind() |
139
|
|
|
{ |
140
|
|
|
$arguments = ['arg2' => 'value2']; |
141
|
|
|
|
142
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|AMQPChannel $adapterChannel */ |
143
|
|
|
$adapterChannel = $this->prophesize(AMQPChannel::class); |
144
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|Channel $channel */ |
145
|
|
|
$channel = $this->prophesize(Channel::class); |
146
|
|
|
$options = $this->getDefaultOptionsProphet(); |
147
|
|
|
|
148
|
|
|
$adapterChannel->queue_unbind('queueName', 'exchangeName', 'routingKey', $arguments)->shouldBeCalled(); |
|
|
|
|
149
|
|
|
$channel->getResource()->willReturn($adapterChannel->reveal()); |
|
|
|
|
150
|
|
|
|
151
|
|
|
$queue = new Queue(); |
152
|
|
|
$queue->setOptions($options->reveal()); |
|
|
|
|
153
|
|
|
$queue->setChannel($channel->reveal()); |
|
|
|
|
154
|
|
|
|
155
|
|
|
static::assertSame($queue, $queue->unbind('exchangeName', 'routingKey', $arguments)); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function testUnbindWithNullRoutingKey() |
159
|
|
|
{ |
160
|
|
|
$arguments = ['arg2' => 'value2']; |
161
|
|
|
|
162
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|AMQPChannel $adapterChannel */ |
163
|
|
|
$adapterChannel = $this->prophesize(AMQPChannel::class); |
164
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|Channel $channel */ |
165
|
|
|
$channel = $this->prophesize(Channel::class); |
166
|
|
|
$options = $this->getDefaultOptionsProphet(); |
167
|
|
|
|
168
|
|
|
$adapterChannel->queue_unbind('queueName', 'exchangeName', '', $arguments)->shouldBeCalled(); |
|
|
|
|
169
|
|
|
$channel->getResource()->willReturn($adapterChannel->reveal()); |
|
|
|
|
170
|
|
|
|
171
|
|
|
$queue = new Queue(); |
172
|
|
|
$queue->setOptions($options->reveal()); |
|
|
|
|
173
|
|
|
$queue->setChannel($channel->reveal()); |
|
|
|
|
174
|
|
|
|
175
|
|
|
static::assertSame($queue, $queue->unbind('exchangeName', null, $arguments)); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
public function testAck() |
179
|
|
|
{ |
180
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|AMQPChannel $adapterChannel */ |
181
|
|
|
$adapterChannel = $this->prophesize(AMQPChannel::class); |
182
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|Channel $channel */ |
183
|
|
|
$channel = $this->prophesize(Channel::class); |
184
|
|
|
$options = $this->getDefaultOptionsProphet(); |
185
|
|
|
|
186
|
|
|
$adapterChannel->basic_ack('deliveryTag', false)->shouldBeCalled(); |
|
|
|
|
187
|
|
|
$channel->getResource()->willReturn($adapterChannel->reveal()); |
|
|
|
|
188
|
|
|
|
189
|
|
|
$queue = new Queue(); |
190
|
|
|
$queue->setOptions($options->reveal()); |
|
|
|
|
191
|
|
|
$queue->setChannel($channel->reveal()); |
|
|
|
|
192
|
|
|
|
193
|
|
|
static::assertSame($queue, $queue->ack('deliveryTag')); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function testAckMultiple() |
197
|
|
|
{ |
198
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|AMQPChannel $adapterChannel */ |
199
|
|
|
$adapterChannel = $this->prophesize(AMQPChannel::class); |
200
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|Channel $channel */ |
201
|
|
|
$channel = $this->prophesize(Channel::class); |
202
|
|
|
$options = $this->getDefaultOptionsProphet(); |
203
|
|
|
|
204
|
|
|
$adapterChannel->basic_ack('deliveryTag', true)->shouldBeCalled(); |
|
|
|
|
205
|
|
|
$channel->getResource()->willReturn($adapterChannel->reveal()); |
|
|
|
|
206
|
|
|
|
207
|
|
|
$queue = new Queue(); |
208
|
|
|
$queue->setOptions($options->reveal()); |
|
|
|
|
209
|
|
|
$queue->setChannel($channel->reveal()); |
|
|
|
|
210
|
|
|
|
211
|
|
|
static::assertSame($queue, $queue->ack('deliveryTag', true)); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
public function testNack() |
215
|
|
|
{ |
216
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|AMQPChannel $adapterChannel */ |
217
|
|
|
$adapterChannel = $this->prophesize(AMQPChannel::class); |
218
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|Channel $channel */ |
219
|
|
|
$channel = $this->prophesize(Channel::class); |
220
|
|
|
$options = $this->getDefaultOptionsProphet(); |
221
|
|
|
|
222
|
|
|
$adapterChannel->basic_nack('deliveryTag', false, false)->shouldBeCalled(); |
|
|
|
|
223
|
|
|
$channel->getResource()->willReturn($adapterChannel->reveal()); |
|
|
|
|
224
|
|
|
|
225
|
|
|
$queue = new Queue(); |
226
|
|
|
$queue->setOptions($options->reveal()); |
|
|
|
|
227
|
|
|
$queue->setChannel($channel->reveal()); |
|
|
|
|
228
|
|
|
|
229
|
|
|
static::assertSame($queue, $queue->nack('deliveryTag')); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
public function testNackRequeue() |
233
|
|
|
{ |
234
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|AMQPChannel $adapterChannel */ |
235
|
|
|
$adapterChannel = $this->prophesize(AMQPChannel::class); |
236
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|Channel $channel */ |
237
|
|
|
$channel = $this->prophesize(Channel::class); |
238
|
|
|
$options = $this->getDefaultOptionsProphet(); |
239
|
|
|
|
240
|
|
|
$adapterChannel->basic_nack('deliveryTag', false, true)->shouldBeCalled(); |
|
|
|
|
241
|
|
|
$channel->getResource()->willReturn($adapterChannel->reveal()); |
|
|
|
|
242
|
|
|
|
243
|
|
|
$queue = new Queue(); |
244
|
|
|
$queue->setOptions($options->reveal()); |
|
|
|
|
245
|
|
|
$queue->setChannel($channel->reveal()); |
|
|
|
|
246
|
|
|
|
247
|
|
|
static::assertSame($queue, $queue->nack('deliveryTag', true)); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
public function testNackMultiple() |
251
|
|
|
{ |
252
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|AMQPChannel $adapterChannel */ |
253
|
|
|
$adapterChannel = $this->prophesize(AMQPChannel::class); |
254
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|Channel $channel */ |
255
|
|
|
$channel = $this->prophesize(Channel::class); |
256
|
|
|
$options = $this->getDefaultOptionsProphet(); |
257
|
|
|
|
258
|
|
|
$adapterChannel->basic_nack('deliveryTag', true, false)->shouldBeCalled(); |
|
|
|
|
259
|
|
|
$channel->getResource()->willReturn($adapterChannel->reveal()); |
|
|
|
|
260
|
|
|
|
261
|
|
|
$queue = new Queue(); |
262
|
|
|
$queue->setOptions($options->reveal()); |
|
|
|
|
263
|
|
|
$queue->setChannel($channel->reveal()); |
|
|
|
|
264
|
|
|
|
265
|
|
|
static::assertSame($queue, $queue->nack('deliveryTag', false, true)); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
public function testNackRequeueMultiple() |
269
|
|
|
{ |
270
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|AMQPChannel $adapterChannel */ |
271
|
|
|
$adapterChannel = $this->prophesize(AMQPChannel::class); |
272
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|Channel $channel */ |
273
|
|
|
$channel = $this->prophesize(Channel::class); |
274
|
|
|
$options = $this->getDefaultOptionsProphet(); |
275
|
|
|
|
276
|
|
|
$adapterChannel->basic_nack('deliveryTag', true, true)->shouldBeCalled(); |
|
|
|
|
277
|
|
|
$channel->getResource()->willReturn($adapterChannel->reveal()); |
|
|
|
|
278
|
|
|
|
279
|
|
|
$queue = new Queue(); |
280
|
|
|
$queue->setOptions($options->reveal()); |
|
|
|
|
281
|
|
|
$queue->setChannel($channel->reveal()); |
|
|
|
|
282
|
|
|
|
283
|
|
|
static::assertSame($queue, $queue->nack('deliveryTag', true, true)); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
public function testReject() |
287
|
|
|
{ |
288
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|AMQPChannel $adapterChannel */ |
289
|
|
|
$adapterChannel = $this->prophesize(AMQPChannel::class); |
290
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|Channel $channel */ |
291
|
|
|
$channel = $this->prophesize(Channel::class); |
292
|
|
|
$options = $this->getDefaultOptionsProphet(); |
293
|
|
|
|
294
|
|
|
$adapterChannel->basic_reject('deliveryTag', false)->shouldBeCalled(); |
|
|
|
|
295
|
|
|
$channel->getResource()->willReturn($adapterChannel->reveal()); |
|
|
|
|
296
|
|
|
|
297
|
|
|
$queue = new Queue(); |
298
|
|
|
$queue->setOptions($options->reveal()); |
|
|
|
|
299
|
|
|
$queue->setChannel($channel->reveal()); |
|
|
|
|
300
|
|
|
|
301
|
|
|
static::assertSame($queue, $queue->reject('deliveryTag')); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
public function testRejectRequeue() |
305
|
|
|
{ |
306
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|AMQPChannel $adapterChannel */ |
307
|
|
|
$adapterChannel = $this->prophesize(AMQPChannel::class); |
308
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|Channel $channel */ |
309
|
|
|
$channel = $this->prophesize(Channel::class); |
310
|
|
|
$options = $this->getDefaultOptionsProphet(); |
311
|
|
|
|
312
|
|
|
$adapterChannel->basic_reject('deliveryTag', true)->shouldBeCalled(); |
|
|
|
|
313
|
|
|
$channel->getResource()->willReturn($adapterChannel->reveal()); |
|
|
|
|
314
|
|
|
|
315
|
|
|
$queue = new Queue(); |
316
|
|
|
$queue->setOptions($options->reveal()); |
|
|
|
|
317
|
|
|
$queue->setChannel($channel->reveal()); |
|
|
|
|
318
|
|
|
|
319
|
|
|
static::assertSame($queue, $queue->reject('deliveryTag', true)); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
public function testPurge() |
323
|
|
|
{ |
324
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|AMQPChannel $adapterChannel */ |
325
|
|
|
$adapterChannel = $this->prophesize(AMQPChannel::class); |
326
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|Channel $channel */ |
327
|
|
|
$channel = $this->prophesize(Channel::class); |
328
|
|
|
$options = $this->getDefaultOptionsProphet(); |
329
|
|
|
|
330
|
|
|
$adapterChannel->queue_purge('queueName')->shouldBeCalled(); |
|
|
|
|
331
|
|
|
$channel->getResource()->willReturn($adapterChannel->reveal()); |
|
|
|
|
332
|
|
|
|
333
|
|
|
$queue = new Queue(); |
334
|
|
|
$queue->setOptions($options->reveal()); |
|
|
|
|
335
|
|
|
$queue->setChannel($channel->reveal()); |
|
|
|
|
336
|
|
|
|
337
|
|
|
static::assertSame($queue, $queue->purge()); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
public function testCancel() |
341
|
|
|
{ |
342
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|AMQPChannel $adapterChannel */ |
343
|
|
|
$adapterChannel = $this->prophesize(AMQPChannel::class); |
344
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|Channel $channel */ |
345
|
|
|
$channel = $this->prophesize(Channel::class); |
346
|
|
|
$options = $this->getDefaultOptionsProphet(); |
347
|
|
|
|
348
|
|
|
$adapterChannel->basic_cancel('consumerTag')->shouldBeCalled(); |
|
|
|
|
349
|
|
|
$channel->getResource()->willReturn($adapterChannel->reveal()); |
|
|
|
|
350
|
|
|
|
351
|
|
|
$queue = new Queue(); |
352
|
|
|
$queue->setOptions($options->reveal()); |
|
|
|
|
353
|
|
|
$queue->setChannel($channel->reveal()); |
|
|
|
|
354
|
|
|
|
355
|
|
|
static::assertSame($queue, $queue->cancel('consumerTag')); |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
public function testGetWithAutoAck() |
359
|
|
|
{ |
360
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|AMQPChannel $adapterChannel */ |
361
|
|
|
$adapterChannel = $this->prophesize(AMQPChannel::class); |
362
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|Channel $channel */ |
363
|
|
|
$channel = $this->prophesize(Channel::class); |
364
|
|
|
$options = $this->getDefaultOptionsProphet(); |
365
|
|
|
$messageMapper = $this->prophesize(MessageMapper::class); |
366
|
|
|
|
367
|
|
|
$messageMapper->toMessage(Argument::any())->shouldNotBeCalled(); |
368
|
|
|
|
369
|
|
|
$adapterChannel->basic_get('queueName', true) |
|
|
|
|
370
|
|
|
->shouldBeCalled() |
371
|
|
|
->willReturn(null); |
372
|
|
|
$channel->getResource()->willReturn($adapterChannel->reveal()); |
|
|
|
|
373
|
|
|
|
374
|
|
|
$queue = new Queue(); |
375
|
|
|
$queue->setOptions($options->reveal()); |
|
|
|
|
376
|
|
|
$queue->setChannel($channel->reveal()); |
|
|
|
|
377
|
|
|
$queue->setMessageMapper($messageMapper->reveal()); |
378
|
|
|
|
379
|
|
|
static::assertNull($queue->get(true)); |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
public function testGetWithAutoAckAndMessage() |
383
|
|
|
{ |
384
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|AMQPChannel $adapterChannel */ |
385
|
|
|
$adapterChannel = $this->prophesize(AMQPChannel::class); |
386
|
|
|
/** @var \Prophecy\Prophecy\ObjectProphecy|Channel $channel */ |
387
|
|
|
$channel = $this->prophesize(Channel::class); |
388
|
|
|
$options = $this->getDefaultOptionsProphet(); |
389
|
|
|
$message = $this->prophesize(Message::class); |
390
|
|
|
$libMessage = $this->prophesize(AMQPMessage::class); |
391
|
|
|
$messageMapper = $this->prophesize(MessageMapper::class); |
392
|
|
|
|
393
|
|
|
$messageMapper->toMessage($libMessage->reveal())->shouldBeCalled()->willReturn($message->reveal()); |
394
|
|
|
|
395
|
|
|
$adapterChannel->basic_get('queueName', true) |
|
|
|
|
396
|
|
|
->shouldBeCalled() |
397
|
|
|
->willReturn($libMessage->reveal()); |
398
|
|
|
$channel->getResource()->willReturn($adapterChannel->reveal()); |
|
|
|
|
399
|
|
|
|
400
|
|
|
$queue = new Queue(); |
401
|
|
|
$queue->setOptions($options->reveal()); |
|
|
|
|
402
|
|
|
$queue->setChannel($channel->reveal()); |
|
|
|
|
403
|
|
|
$queue->setMessageMapper($messageMapper->reveal()); |
404
|
|
|
|
405
|
|
|
static::assertSame($message->reveal(), $queue->get(true)); |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
/** |
409
|
|
|
* @dataProvider consumeProvider |
410
|
|
|
*/ |
411
|
|
|
public function testConsume($args, $libArgs) |
412
|
|
|
{ |
413
|
|
|
$adapterChannel = $this->prophesize(AMQPChannel::class); |
414
|
|
|
$channel = $this->prophesize(Channel::class); |
415
|
|
|
$options = $this->getDefaultOptionsProphet(); |
416
|
|
|
$libMessage = $this->prophesize(AMQPMessage::class); |
417
|
|
|
$messageMapper = $this->prophesize(MessageMapper::class); |
418
|
|
|
|
419
|
|
|
$adapterChannel->basic_consume( |
420
|
|
|
'queueName', |
421
|
|
|
$libArgs[3], |
422
|
|
|
$libArgs[0], |
423
|
|
|
$libArgs[1], |
424
|
|
|
$libArgs[2], |
425
|
|
|
false, |
426
|
|
|
Argument::type(ConsumerCallback::class) |
427
|
|
|
) |
428
|
|
|
->shouldBeCalled() |
429
|
|
|
->willReturn($libMessage->reveal()); |
430
|
|
|
|
431
|
|
|
$adapterChannel->callbacks = ['foo', 'bar']; |
432
|
|
|
$adapterChannel->wait()->shouldBeCalledTimes(count($adapterChannel->callbacks)) |
433
|
|
|
->will(function () use ($adapterChannel) { |
434
|
|
|
$callbacks = $adapterChannel->callbacks; |
435
|
|
|
array_shift($callbacks); |
436
|
|
|
$adapterChannel->callbacks = $callbacks; |
437
|
|
|
}); |
438
|
|
|
|
439
|
|
|
$channel->getResource()->willReturn($adapterChannel->reveal()); |
440
|
|
|
|
441
|
|
|
$queue = new Queue(); |
442
|
|
|
$queue->setOptions($options->reveal()); |
|
|
|
|
443
|
|
|
$queue->setChannel($channel->reveal()); |
444
|
|
|
$queue->setMessageMapper($messageMapper->reveal()); |
445
|
|
|
|
446
|
|
|
$callback = function () { |
447
|
|
|
|
448
|
|
|
}; |
449
|
|
|
|
450
|
|
|
$ret = $queue->consume($callback, $args[0], $args[1], $args[2], $args[3]); |
451
|
|
|
|
452
|
|
|
static::assertSame($queue, $ret); |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
public function consumeProvider() |
456
|
|
|
{ |
457
|
|
|
return [ |
458
|
|
|
[ |
459
|
|
|
[true, true, true, null], |
460
|
|
|
[true, true, true, ''], |
461
|
|
|
], |
462
|
|
|
[ |
463
|
|
|
[true, true, true, 'consumerTag'], |
464
|
|
|
[true, true, true, 'consumerTag'], |
465
|
|
|
], |
466
|
|
|
[ |
467
|
|
|
[false, false, false, 'consumerTag'], |
468
|
|
|
[false, false, false, 'consumerTag'], |
469
|
|
|
], |
470
|
|
|
]; |
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
public function testSetAndGetChannel() |
474
|
|
|
{ |
475
|
|
|
$channel = $this->prophesize(Channel::class); |
476
|
|
|
|
477
|
|
|
$exchange = new Queue(); |
478
|
|
|
static::assertSame($exchange, $exchange->setChannel($channel->reveal())); |
479
|
|
|
static::assertSame($channel->reveal(), $exchange->getChannel()); |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
public function testGetConnection() |
483
|
|
|
{ |
484
|
|
|
$channel = $this->prophesize(Channel::class); |
485
|
|
|
$connection = $this->prophesize(Connection::class); |
486
|
|
|
|
487
|
|
|
$channel->getConnection()->willReturn($connection); |
488
|
|
|
|
489
|
|
|
$exchange = new Queue(); |
490
|
|
|
static::assertSame($exchange, $exchange->setChannel($channel->reveal())); |
491
|
|
|
static::assertSame($connection->reveal(), $exchange->getConnection()); |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
public function deleteProvider() |
495
|
|
|
{ |
496
|
|
|
return [ |
497
|
|
|
[true, true, true], |
498
|
|
|
[true, true, false], |
499
|
|
|
[true, false, true], |
500
|
|
|
[true, false, false], |
501
|
|
|
[false, true, true], |
502
|
|
|
[false, true, false], |
503
|
|
|
[false, false, true], |
504
|
|
|
[false, false, false], |
505
|
|
|
]; |
506
|
|
|
} |
507
|
|
|
|
508
|
|
|
/** |
509
|
|
|
* @return Options\QueueOptions|\Prophecy\Prophecy\ObjectProphecy |
510
|
|
|
*/ |
511
|
|
|
protected function getDefaultOptionsProphet() |
512
|
|
|
{ |
513
|
|
|
/** @var Options\QueueOptions|\Prophecy\Prophecy\ObjectProphecy $options */ |
514
|
|
|
$options = $this->prophesize(Options\QueueOptions::class); |
515
|
|
|
|
516
|
|
|
$options->isDurable()->willReturn(true); |
|
|
|
|
517
|
|
|
$options->isPassive()->willReturn(true); |
|
|
|
|
518
|
|
|
$options->isAutoDelete()->willReturn(true); |
|
|
|
|
519
|
|
|
$options->isExclusive()->willReturn(true); |
|
|
|
|
520
|
|
|
$options->getName()->willReturn('queueName'); |
|
|
|
|
521
|
|
|
$options->getArguments()->willReturn(['arg1' => 'value1']); |
|
|
|
|
522
|
|
|
$options->isExclusive()->willReturn(true); |
523
|
|
|
|
524
|
|
|
return $options; |
525
|
|
|
} |
526
|
|
|
} |
527
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: