@@ -220,34 +220,42 @@ public function testRunWithAllOption()
220220 $ envelope2 = new Envelope (new \stdClass (), [new BusNameStamp ('dummy-bus ' )]);
221221
222222 $ receiver1 = $ this ->createMock (ReceiverInterface::class);
223- $ receiver1 ->expects ( $ this -> once ())-> method ('get ' )->willReturn ([$ envelope1 ]);
223+ $ receiver1 ->method ('get ' )->willReturn ([$ envelope1 ]);
224224 $ receiver2 = $ this ->createMock (ReceiverInterface::class);
225- $ receiver2 ->expects ( $ this -> once ())-> method ('get ' )->willReturn ([$ envelope2 ]);
225+ $ receiver2 ->method ('get ' )->willReturn ([$ envelope2 ]);
226226
227227 $ receiverLocator = $ this ->createMock (ContainerInterface::class);
228- $ receiverLocator ->expects ($ this ->once ())->method ('has ' )->with ('dummy-receiver1 ' )->willReturn (true );
229- $ receiverLocator ->expects ($ this ->once ())->method ('get ' )->with ('dummy-receiver1 ' )->willReturn ($ receiver1 );
230- $ receiverLocator ->expects ($ this ->once ())->method ('has ' )->with ('dummy-receiver2 ' )->willReturn (true );
231- $ receiverLocator ->expects ($ this ->once ())->method ('get ' )->with ('dummy-receiver2 ' )->willReturn ($ receiver2 );
228+ $ receiverLocator ->expects ($ this ->exactly (2 ))
229+ ->method ('has ' )
230+ ->willReturnCallback (static fn (string $ id ): bool => \in_array ($ id , ['dummy-receiver1 ' , 'dummy-receiver2 ' ], true ));
231+
232+ $ receiverLocator ->expects ($ this ->exactly (2 ))
233+ ->method ('get ' )
234+ ->willReturnCallback (static fn (string $ id ): ReceiverInterface => 'dummy-receiver1 ' === $ id ? $ receiver1 : $ receiver2 );
232235
233236 $ bus = $ this ->createMock (MessageBusInterface::class);
234237 $ bus ->expects ($ this ->exactly (2 ))->method ('dispatch ' );
235238
236239 $ busLocator = $ this ->createMock (ContainerInterface::class);
237- $ busLocator ->expects ($ this ->once ( ))->method ('has ' )->with ('dummy-bus ' )->willReturn (true );
238- $ busLocator ->expects ($ this ->once ( ))->method ('get ' )->with ('dummy-bus ' )->willReturn ($ bus );
240+ $ busLocator ->expects ($ this ->exactly ( 2 ))->method ('has ' )->with ('dummy-bus ' )->willReturn (true );
241+ $ busLocator ->expects ($ this ->exactly ( 2 ))->method ('get ' )->with ('dummy-bus ' )->willReturn ($ bus );
239242
240- $ command = new ConsumeMessagesCommand (new RoutableMessageBus ($ busLocator ), $ receiverLocator , new EventDispatcher ());
243+ $ command = new ConsumeMessagesCommand (
244+ new RoutableMessageBus ($ busLocator ),
245+ $ receiverLocator , new EventDispatcher (),
246+ receiverNames: ['dummy-receiver1 ' , 'dummy-receiver2 ' ]
247+ );
241248
242249 $ application = new Application ();
243250 $ application ->add ($ command );
244251 $ tester = new CommandTester ($ application ->get ('messenger:consume ' ));
245252 $ tester ->execute ([
246- '--all ' => null ,
253+ '--all ' => true ,
254+ '--limit ' => 2 ,
247255 ]);
248256
249257 $ tester ->assertCommandIsSuccessful ();
250- $ this ->assertStringContainsString ('[OK] Consuming messages from transport "dummy-receiver1, dummy-receiver2" ' , $ tester ->getDisplay ());
258+ $ this ->assertStringContainsString ('[OK] Consuming messages from transports "dummy-receiver1, dummy-receiver2" ' , $ tester ->getDisplay ());
251259 }
252260
253261 /**
0 commit comments