@@ -95,11 +95,7 @@ public function testRunWithBusOption()
95
95
$ command = new ConsumeMessagesCommand (new RoutableMessageBus ($ busLocator ), $ receiverLocator , new EventDispatcher ());
96
96
97
97
$ application = new Application ();
98
- if (method_exists ($ application , 'addCommand ' )) {
99
- $ application ->addCommand ($ command );
100
- } else {
101
- $ application ->add ($ command );
102
- }
98
+ $ application ->add ($ command );
103
99
$ tester = new CommandTester ($ application ->get ('messenger:consume ' ));
104
100
$ tester ->execute ([
105
101
'receivers ' => ['dummy-receiver ' ],
@@ -142,11 +138,7 @@ public function testRunWithResetServicesOption(bool $shouldReset)
142
138
$ command = new ConsumeMessagesCommand ($ bus , $ receiverLocator , new EventDispatcher (), null , [], new ResetServicesListener ($ servicesResetter ));
143
139
144
140
$ application = new Application ();
145
- if (method_exists ($ application , 'addCommand ' )) {
146
- $ application ->addCommand ($ command );
147
- } else {
148
- $ application ->add ($ command );
149
- }
141
+ $ application ->add ($ command );
150
142
$ tester = new CommandTester ($ application ->get ('messenger:consume ' ));
151
143
$ tester ->execute (array_merge ([
152
144
'receivers ' => ['dummy-receiver ' ],
@@ -170,11 +162,7 @@ public function testRunWithInvalidOption(string $option, string $value, string $
170
162
$ command = new ConsumeMessagesCommand (new RoutableMessageBus (new Container ()), $ receiverLocator , new EventDispatcher ());
171
163
172
164
$ application = new Application ();
173
- if (method_exists ($ application , 'addCommand ' )) {
174
- $ application ->addCommand ($ command );
175
- } else {
176
- $ application ->add ($ command );
177
- }
165
+ $ application ->add ($ command );
178
166
$ tester = new CommandTester ($ application ->get ('messenger:consume ' ));
179
167
180
168
$ this ->expectException (InvalidOptionException::class);
@@ -212,11 +200,7 @@ public function testRunWithTimeLimit()
212
200
$ command = new ConsumeMessagesCommand (new RoutableMessageBus ($ busLocator ), $ receiverLocator , new EventDispatcher ());
213
201
214
202
$ application = new Application ();
215
- if (method_exists ($ application , 'addCommand ' )) {
216
- $ application ->addCommand ($ command );
217
- } else {
218
- $ application ->add ($ command );
219
- }
203
+ $ application ->add ($ command );
220
204
$ tester = new CommandTester ($ application ->get ('messenger:consume ' ));
221
205
$ tester ->execute ([
222
206
'receivers ' => ['dummy-receiver ' ],
@@ -255,11 +239,7 @@ public function log(...$args): void
255
239
$ command = new ConsumeMessagesCommand (new RoutableMessageBus ($ busLocator ), $ receiverLocator , new EventDispatcher (), $ logger );
256
240
257
241
$ application = new Application ();
258
- if (method_exists ($ application , 'addCommand ' )) {
259
- $ application ->addCommand ($ command );
260
- } else {
261
- $ application ->add ($ command );
262
- }
242
+ $ application ->add ($ command );
263
243
$ tester = new CommandTester ($ application ->get ('messenger:consume ' ));
264
244
$ tester ->execute ([
265
245
'receivers ' => ['dummy-receiver ' ],
@@ -300,11 +280,7 @@ public function testRunWithAllOption()
300
280
);
301
281
302
282
$ application = new Application ();
303
- if (method_exists ($ application , 'addCommand ' )) {
304
- $ application ->addCommand ($ command );
305
- } else {
306
- $ application ->add ($ command );
307
- }
283
+ $ application ->add ($ command );
308
284
$ tester = new CommandTester ($ application ->get ('messenger:consume ' ));
309
285
$ tester ->execute ([
310
286
'--all ' => true ,
@@ -315,6 +291,92 @@ public function testRunWithAllOption()
315
291
$ this ->assertStringContainsString ('[OK] Consuming messages from transports "dummy-receiver1, dummy-receiver2" ' , $ tester ->getDisplay ());
316
292
}
317
293
294
+ public function testRunWithAllAndExcludeQueuesOption ()
295
+ {
296
+ $ envelope1 = new Envelope (new \stdClass (), [new BusNameStamp ('dummy-bus ' )]);
297
+ $ envelope2 = new Envelope (new \stdClass (), [new BusNameStamp ('dummy-bus ' )]);
298
+ $ envelope3 = new Envelope (new \stdClass (), [new BusNameStamp ('dummy-bus ' )]);
299
+
300
+ $ receiver1 = $ this ->createMock (ReceiverInterface::class);
301
+ $ receiver1 ->method ('get ' )->willReturn ([$ envelope1 ]);
302
+ $ receiver2 = $ this ->createMock (ReceiverInterface::class);
303
+ $ receiver2 ->method ('get ' )->willReturn ([$ envelope2 ]);
304
+ $ receiver3 = $ this ->createMock (ReceiverInterface::class);
305
+ $ receiver3 ->method ('get ' )->willReturn ([$ envelope3 ]);
306
+
307
+ $ receiverLocator = new Container ();
308
+ $ receiverLocator ->set ('dummy-receiver1 ' , $ receiver1 );
309
+ $ receiverLocator ->set ('dummy-receiver2 ' , $ receiver2 );
310
+ $ receiverLocator ->set ('dummy-receiver3 ' , $ receiver3 );
311
+
312
+ $ bus = $ this ->createMock (MessageBusInterface::class);
313
+ $ bus ->expects ($ this ->exactly (2 ))->method ('dispatch ' );
314
+
315
+ $ busLocator = new Container ();
316
+ $ busLocator ->set ('dummy-bus ' , $ bus );
317
+
318
+ $ command = new ConsumeMessagesCommand (
319
+ new RoutableMessageBus ($ busLocator ),
320
+ $ receiverLocator , new EventDispatcher (),
321
+ receiverNames: ['dummy-receiver1 ' , 'dummy-receiver2 ' , 'dummy-receiver3 ' ]
322
+ );
323
+
324
+ $ application = new Application ();
325
+ $ application ->add ($ command );
326
+ $ tester = new CommandTester ($ application ->get ('messenger:consume ' ));
327
+ $ tester ->execute ([
328
+ '--all ' => true ,
329
+ '--exclude-queues ' => ['dummy-receiver2 ' ],
330
+ '--limit ' => 2 ,
331
+ ]);
332
+
333
+ $ tester ->assertCommandIsSuccessful ();
334
+ $ this ->assertStringContainsString ('[OK] Consuming messages from transports "dummy-receiver1, dummy-receiver3" ' , $ tester ->getDisplay ());
335
+ }
336
+
337
+ public function testRunWithExcludeQueuesWithoutAllOption ()
338
+ {
339
+ $ receiverLocator = new Container ();
340
+ $ receiverLocator ->set ('dummy-receiver ' , new \stdClass ());
341
+
342
+ $ command = new ConsumeMessagesCommand (new RoutableMessageBus (new Container ()), $ receiverLocator , new EventDispatcher ());
343
+
344
+ $ application = new Application ();
345
+ $ application ->add ($ command );
346
+ $ tester = new CommandTester ($ application ->get ('messenger:consume ' ));
347
+
348
+ $ this ->expectException (InvalidOptionException::class);
349
+ $ this ->expectExceptionMessage ('The --exclude-queues option can only be used with the --all option. ' );
350
+ $ tester ->execute ([
351
+ 'receivers ' => ['dummy-receiver ' ],
352
+ '--exclude-queues ' => ['dummy-receiver ' ],
353
+ ]);
354
+ }
355
+
356
+ public function testRunWithAllAndExcludeAllQueues ()
357
+ {
358
+ $ receiverLocator = new Container ();
359
+ $ receiverLocator ->set ('dummy-receiver1 ' , new \stdClass ());
360
+ $ receiverLocator ->set ('dummy-receiver2 ' , new \stdClass ());
361
+
362
+ $ command = new ConsumeMessagesCommand (
363
+ new RoutableMessageBus (new Container ()),
364
+ $ receiverLocator , new EventDispatcher (),
365
+ receiverNames: ['dummy-receiver1 ' , 'dummy-receiver2 ' ]
366
+ );
367
+
368
+ $ application = new Application ();
369
+ $ application ->add ($ command );
370
+ $ tester = new CommandTester ($ application ->get ('messenger:consume ' ));
371
+
372
+ $ this ->expectException (\Symfony \Component \Console \Exception \RuntimeException::class);
373
+ $ this ->expectExceptionMessage ('All queues have been excluded. Please specify at least one queue to consume from. ' );
374
+ $ tester ->execute ([
375
+ '--all ' => true ,
376
+ '--exclude-queues ' => ['dummy-receiver1 ' , 'dummy-receiver2 ' ],
377
+ ]);
378
+ }
379
+
318
380
/**
319
381
* @dataProvider provideCompletionSuggestions
320
382
*/
@@ -333,5 +395,7 @@ public static function provideCompletionSuggestions()
333
395
yield 'receiver (value) ' => [['async ' ], ['async ' , 'async_high ' , 'failed ' ]];
334
396
yield 'receiver (no repeat) ' => [['async ' , '' ], ['async_high ' , 'failed ' ]];
335
397
yield 'option --bus ' => [['--bus ' , '' ], ['messenger.bus.default ' ]];
398
+ yield 'option --exclude-queues ' => [['--exclude-queues ' , '' ], ['async ' , 'async_high ' , 'failed ' ]];
399
+ yield 'option --exclude-queues (value) ' => [['--exclude-queues ' , 'async ' ], ['async ' , 'async_high ' , 'failed ' ]];
336
400
}
337
401
}
0 commit comments