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