From 36307a042a59318ef2c80982b26a17590c0e9388 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Tue, 5 Dec 2023 10:51:36 +0100 Subject: [PATCH] [Messenger] Fix test on `messenger:consume` with `--all` option --- .../Command/ConsumeMessagesCommandTest.php | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Component/Messenger/Tests/Command/ConsumeMessagesCommandTest.php b/src/Symfony/Component/Messenger/Tests/Command/ConsumeMessagesCommandTest.php index 40579ece6fa21..b7f33f2fcbd25 100644 --- a/src/Symfony/Component/Messenger/Tests/Command/ConsumeMessagesCommandTest.php +++ b/src/Symfony/Component/Messenger/Tests/Command/ConsumeMessagesCommandTest.php @@ -220,34 +220,42 @@ public function testRunWithAllOption() $envelope2 = new Envelope(new \stdClass(), [new BusNameStamp('dummy-bus')]); $receiver1 = $this->createMock(ReceiverInterface::class); - $receiver1->expects($this->once())->method('get')->willReturn([$envelope1]); + $receiver1->method('get')->willReturn([$envelope1]); $receiver2 = $this->createMock(ReceiverInterface::class); - $receiver2->expects($this->once())->method('get')->willReturn([$envelope2]); + $receiver2->method('get')->willReturn([$envelope2]); $receiverLocator = $this->createMock(ContainerInterface::class); - $receiverLocator->expects($this->once())->method('has')->with('dummy-receiver1')->willReturn(true); - $receiverLocator->expects($this->once())->method('get')->with('dummy-receiver1')->willReturn($receiver1); - $receiverLocator->expects($this->once())->method('has')->with('dummy-receiver2')->willReturn(true); - $receiverLocator->expects($this->once())->method('get')->with('dummy-receiver2')->willReturn($receiver2); + $receiverLocator->expects($this->exactly(2)) + ->method('has') + ->willReturnCallback(static fn (string $id): bool => \in_array($id, ['dummy-receiver1', 'dummy-receiver2'], true)); + + $receiverLocator->expects($this->exactly(2)) + ->method('get') + ->willReturnCallback(static fn (string $id): ReceiverInterface => 'dummy-receiver1' === $id ? $receiver1 : $receiver2); $bus = $this->createMock(MessageBusInterface::class); $bus->expects($this->exactly(2))->method('dispatch'); $busLocator = $this->createMock(ContainerInterface::class); - $busLocator->expects($this->once())->method('has')->with('dummy-bus')->willReturn(true); - $busLocator->expects($this->once())->method('get')->with('dummy-bus')->willReturn($bus); + $busLocator->expects($this->exactly(2))->method('has')->with('dummy-bus')->willReturn(true); + $busLocator->expects($this->exactly(2))->method('get')->with('dummy-bus')->willReturn($bus); - $command = new ConsumeMessagesCommand(new RoutableMessageBus($busLocator), $receiverLocator, new EventDispatcher()); + $command = new ConsumeMessagesCommand( + new RoutableMessageBus($busLocator), + $receiverLocator, new EventDispatcher(), + receiverNames: ['dummy-receiver1', 'dummy-receiver2'] + ); $application = new Application(); $application->add($command); $tester = new CommandTester($application->get('messenger:consume')); $tester->execute([ - '--all' => null, + '--all' => true, + '--limit' => 2, ]); $tester->assertCommandIsSuccessful(); - $this->assertStringContainsString('[OK] Consuming messages from transport "dummy-receiver1, dummy-receiver2"', $tester->getDisplay()); + $this->assertStringContainsString('[OK] Consuming messages from transports "dummy-receiver1, dummy-receiver2"', $tester->getDisplay()); } /**