Skip to content

Commit 63221f0

Browse files
bug symfony#48198 [Messenger] Fix time-limit check exception (alamirault)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Messenger] Fix time-limit check exception | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix symfony#48196 <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Check on `time-limit` was invalid. (Unrelated fabbot failure) Commits ------- a13b41a [Messenger] Fix time-limit check exception
2 parents 2e3ffe2 + a13b41a commit 63221f0

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
179179
}
180180

181181
if (null !== ($timeLimit = $input->getOption('time-limit'))) {
182-
if (!is_numeric($timeLimit) || 0 >= $limit) {
182+
if (!is_numeric($timeLimit) || 0 >= $timeLimit) {
183183
throw new InvalidOptionException(sprintf('Option "time-limit" must be a positive integer, "%s" passed.', $timeLimit));
184184
}
185185

src/Symfony/Component/Messenger/Tests/Command/ConsumeMessagesCommandTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)