$msgCount = 3;
$receiverLocator =
$this->
createMock(ContainerInterface::
class);
$receiverLocator->
expects($this->
once())->
method('has'
)->
with('dummy-receiver'
)->
willReturn(true
);
$receiverLocator->
expects($this->
once())->
method('get'
)->
with('dummy-receiver'
)->
willReturn($receiver);
$bus =
$this->
createMock(RoutableMessageBus::
class);
$bus->
expects($this->
exactly($msgCount))->
method('dispatch'
);
$servicesResetter =
new ServicesResetter(new \
ArrayIterator([$receiver]),
['reset'
]);
$command =
new ConsumeMessagesCommand($bus,
$receiverLocator,
new EventDispatcher(), null,
[],
new ResetServicesListener($servicesResetter));
$application =
new Application();
$application->
add($command);
$tester =
new CommandTester($application->
get('messenger:consume'
));
$tester->
execute(array_merge([ 'receivers' =>
['dummy-receiver'
],
'--sleep' => '0.001', // do not sleep too long
'--limit' =>
$msgCount,
],
$shouldReset ?
[] :
['--no-reset' => null
]));
$this->
assertEquals($shouldReset,
$receiver->
hasBeenReset(), '$receiver->reset() should have been called'
);