@@ -206,4 +206,35 @@ public function getInvalidOptions()
206206 yield 'Zero second time limit ' => ['--time-limit ' , '0 ' , 'Option "time-limit" must be a positive integer, "0" passed. ' ];
207207 yield 'Non-numeric time limit ' => ['--time-limit ' , 'whatever ' , 'Option "time-limit" must be a positive integer, "whatever" passed. ' ];
208208 }
209+
210+ public function testRunWithTimeLimit ()
211+ {
212+ $ envelope = new Envelope (new \stdClass (), [new BusNameStamp ('dummy-bus ' )]);
213+
214+ $ receiver = $ this ->createMock (ReceiverInterface::class);
215+ $ receiver ->method ('get ' )->willReturn ([$ envelope ]);
216+
217+ $ receiverLocator = $ this ->createMock (ContainerInterface::class);
218+ $ receiverLocator ->method ('has ' )->with ('dummy-receiver ' )->willReturn (true );
219+ $ receiverLocator ->method ('get ' )->with ('dummy-receiver ' )->willReturn ($ receiver );
220+
221+ $ bus = $ this ->createMock (MessageBusInterface::class);
222+
223+ $ busLocator = $ this ->createMock (ContainerInterface::class);
224+ $ busLocator ->method ('has ' )->with ('dummy-bus ' )->willReturn (true );
225+ $ busLocator ->method ('get ' )->with ('dummy-bus ' )->willReturn ($ bus );
226+
227+ $ command = new ConsumeMessagesCommand (new RoutableMessageBus ($ busLocator ), $ receiverLocator , new EventDispatcher ());
228+
229+ $ application = new Application ();
230+ $ application ->add ($ command );
231+ $ tester = new CommandTester ($ application ->get ('messenger:consume ' ));
232+ $ tester ->execute ([
233+ 'receivers ' => ['dummy-receiver ' ],
234+ '--time-limit ' => 1 ,
235+ ]);
236+
237+ $ this ->assertSame (0 , $ tester ->getStatusCode ());
238+ $ this ->assertStringContainsString ('[OK] Consuming messages from transports "dummy-receiver" ' , $ tester ->getDisplay ());
239+ }
209240}
0 commit comments