@@ -143,7 +143,7 @@ public function consumeProvider()
143
143
*/
144
144
public function testConsume (array $ data )
145
145
{
146
- $ consumerCallBacks = $ data ['messages ' ];
146
+ $ messageCount = count ( $ data ['messages ' ]) ;
147
147
148
148
// set up amqp connection
149
149
$ amqpConnection = $ this ->prepareAMQPConnection ();
@@ -153,38 +153,38 @@ public function testConsume(array $data)
153
153
->method ('getChannelId ' )
154
154
->with ()
155
155
->willReturn (true );
156
- $ amqpChannel ->expects ($ this ->once ())
156
+ $ amqpChannel
157
+ ->expects ($ this ->once ())
157
158
->method ('basic_consume ' )
158
159
->withAnyParameters ()
159
160
->willReturn (true );
161
+ $ amqpChannel
162
+ ->expects (self ::exactly (2 ))
163
+ ->method ('is_consuming ' )
164
+ ->willReturnOnConsecutiveCalls (array_merge (array_fill (0 , $ messageCount , true ), [false ]));
160
165
161
166
// set up consumer
162
167
$ consumer = $ this ->getConsumer ($ amqpConnection , $ amqpChannel );
163
168
// disable autosetup fabric so we do not mock more objects
164
169
$ consumer ->disableAutoSetupFabric ();
165
170
$ consumer ->setChannel ($ amqpChannel );
166
- $ amqpChannel ->callbacks = $ consumerCallBacks ;
167
171
168
172
/**
169
173
* Mock wait method and use a callback to remove one element each time from callbacks
170
174
* This will simulate a basic consumer consume with provided messages count
171
175
*/
172
- $ amqpChannel ->expects ($ this ->exactly (count ($ consumerCallBacks )))
176
+ $ amqpChannel
177
+ ->expects (self ::exactly (1 ))
173
178
->method ('wait ' )
174
179
->with (null , false , $ consumer ->getIdleTimeout ())
175
- ->will (
176
- $ this ->returnCallback (
177
- function () use ($ amqpChannel ) {
178
- /** remove an element on each loop like ... simulate an ACK */
179
- array_splice ($ amqpChannel ->callbacks , 0 , 1 );
180
- })
181
- );
180
+ ->willReturn (true );
182
181
183
182
$ eventDispatcher = $ this ->getMockBuilder (EventDispatcherInterface::class)
184
183
->disableOriginalConstructor ()
185
184
->getMock ();
186
185
187
- $ eventDispatcher ->expects ($ this ->exactly (count ($ consumerCallBacks )))
186
+ $ eventDispatcher
187
+ ->expects (self ::exactly (1 ))
188
188
->method ('dispatch ' )
189
189
->with ($ this ->isInstanceOf (OnConsumeEvent::class), OnConsumeEvent::NAME )
190
190
->willReturn ($ this ->isInstanceOf (OnConsumeEvent::class));
@@ -207,6 +207,10 @@ public function testIdleTimeoutExitCode()
207
207
->method ('basic_consume ' )
208
208
->withAnyParameters ()
209
209
->willReturn (true );
210
+ $ amqpChannel
211
+ ->expects ($ this ->any ())
212
+ ->method ('is_consuming ' )
213
+ ->willReturn (true );
210
214
211
215
// set up consumer
212
216
$ consumer = $ this ->getConsumer ($ amqpConnection , $ amqpChannel );
@@ -215,7 +219,6 @@ public function testIdleTimeoutExitCode()
215
219
$ consumer ->setChannel ($ amqpChannel );
216
220
$ consumer ->setIdleTimeout (60 );
217
221
$ consumer ->setIdleTimeoutExitCode (2 );
218
- $ amqpChannel ->callbacks = array ('idle_timeout_exit_code ' );
219
222
220
223
$ amqpChannel ->expects ($ this ->exactly (1 ))
221
224
->method ('wait ' )
@@ -243,14 +246,17 @@ public function testShouldAllowContinueConsumptionAfterIdleTimeout()
243
246
->method ('basic_consume ' )
244
247
->withAnyParameters ()
245
248
->willReturn (true );
249
+ $ amqpChannel
250
+ ->expects ($ this ->any ())
251
+ ->method ('is_consuming ' )
252
+ ->willReturn (true );
246
253
247
254
// set up consumer
248
255
$ consumer = $ this ->getConsumer ($ amqpConnection , $ amqpChannel );
249
256
// disable autosetup fabric so we do not mock more objects
250
257
$ consumer ->disableAutoSetupFabric ();
251
258
$ consumer ->setChannel ($ amqpChannel );
252
259
$ consumer ->setIdleTimeout (2 );
253
- $ amqpChannel ->callbacks = array ('idle_timeout_exit_code ' );
254
260
255
261
$ amqpChannel ->expects ($ this ->exactly (2 ))
256
262
->method ('wait ' )
@@ -303,6 +309,10 @@ public function testGracefulMaxExecutionTimeoutExitCode()
303
309
->method ('basic_consume ' )
304
310
->withAnyParameters ()
305
311
->willReturn (true );
312
+ $ amqpChannel
313
+ ->expects ($ this ->any ())
314
+ ->method ('is_consuming ' )
315
+ ->willReturn (true );
306
316
307
317
// set up consumer
308
318
$ consumer = $ this ->getConsumer ($ amqpConnection , $ amqpChannel );
@@ -312,7 +322,6 @@ public function testGracefulMaxExecutionTimeoutExitCode()
312
322
313
323
$ consumer ->setGracefulMaxExecutionDateTimeFromSecondsInTheFuture (60 );
314
324
$ consumer ->setGracefulMaxExecutionTimeoutExitCode (10 );
315
- $ amqpChannel ->callbacks = array ('graceful_max_execution_timeout_test ' );
316
325
317
326
$ amqpChannel ->expects ($ this ->exactly (1 ))
318
327
->method ('wait ' )
@@ -339,6 +348,10 @@ public function testGracefulMaxExecutionWontWaitIfPastTheTimeout()
339
348
->method ('basic_consume ' )
340
349
->withAnyParameters ()
341
350
->willReturn (true );
351
+ $ amqpChannel
352
+ ->expects ($ this ->any ())
353
+ ->method ('is_consuming ' )
354
+ ->willReturn (true );
342
355
343
356
// set up consumer
344
357
$ consumer = $ this ->getConsumer ($ amqpConnection , $ amqpChannel );
@@ -347,9 +360,9 @@ public function testGracefulMaxExecutionWontWaitIfPastTheTimeout()
347
360
$ consumer ->setChannel ($ amqpChannel );
348
361
349
362
$ consumer ->setGracefulMaxExecutionDateTimeFromSecondsInTheFuture (0 );
350
- $ amqpChannel ->callbacks = array ('graceful_max_execution_timeout_test ' );
351
363
352
- $ amqpChannel ->expects ($ this ->never ())
364
+ $ amqpChannel
365
+ ->expects ($ this ->never ())
353
366
->method ('wait ' );
354
367
355
368
$ consumer ->consume (1 );
@@ -369,6 +382,10 @@ public function testTimeoutWait()
369
382
->method ('basic_consume ' )
370
383
->withAnyParameters ()
371
384
->willReturn (true );
385
+ $ amqpChannel
386
+ ->expects ($ this ->any ())
387
+ ->method ('is_consuming ' )
388
+ ->willReturn (true );
372
389
373
390
// set up consumer
374
391
$ consumer = $ this ->getConsumer ($ amqpConnection , $ amqpChannel );
@@ -379,8 +396,6 @@ public function testTimeoutWait()
379
396
$ consumer ->setGracefulMaxExecutionDateTimeFromSecondsInTheFuture (60 );
380
397
$ consumer ->setIdleTimeout (50 );
381
398
382
- $ amqpChannel ->callbacks = array ('timeout_wait_test ' );
383
-
384
399
$ amqpChannel ->expects ($ this ->exactly (2 ))
385
400
->method ('wait ' )
386
401
->with (null , false , $ this ->LessThanOrEqual ($ consumer ->getTimeoutWait ()) )
@@ -411,6 +426,10 @@ public function testTimeoutWaitWontWaitPastGracefulMaxExecutionTimeout()
411
426
->method ('basic_consume ' )
412
427
->withAnyParameters ()
413
428
->willReturn (true );
429
+ $ amqpChannel
430
+ ->expects ($ this ->any ())
431
+ ->method ('is_consuming ' )
432
+ ->willReturn (true );
414
433
415
434
// set up consumer
416
435
$ consumer = $ this ->getConsumer ($ amqpConnection , $ amqpChannel );
@@ -420,7 +439,6 @@ public function testTimeoutWaitWontWaitPastGracefulMaxExecutionTimeout()
420
439
$ consumer ->setTimeoutWait (20 );
421
440
422
441
$ consumer ->setGracefulMaxExecutionDateTimeFromSecondsInTheFuture (10 );
423
- $ amqpChannel ->callbacks = array ('graceful_max_execution_timeout_test ' );
424
442
425
443
$ amqpChannel ->expects ($ this ->once ())
426
444
->method ('wait ' )
@@ -448,6 +466,10 @@ public function testTimeoutWaitWontWaitPastIdleTimeout()
448
466
->method ('basic_consume ' )
449
467
->withAnyParameters ()
450
468
->willReturn (true );
469
+ $ amqpChannel
470
+ ->expects ($ this ->any ())
471
+ ->method ('is_consuming ' )
472
+ ->willReturn (true );
451
473
452
474
// set up consumer
453
475
$ consumer = $ this ->getConsumer ($ amqpConnection , $ amqpChannel );
@@ -458,8 +480,6 @@ public function testTimeoutWaitWontWaitPastIdleTimeout()
458
480
$ consumer ->setIdleTimeout (10 );
459
481
$ consumer ->setIdleTimeoutExitCode (2 );
460
482
461
- $ amqpChannel ->callbacks = array ('idle_timeout_test ' );
462
-
463
483
$ amqpChannel ->expects ($ this ->once ())
464
484
->method ('wait ' )
465
485
->with (null , false , 10 )
0 commit comments