diff --git a/src/Symfony/Component/Messenger/Command/SetupTransportsCommand.php b/src/Symfony/Component/Messenger/Command/SetupTransportsCommand.php index 98dcfd9e9936..d535cc9c429a 100644 --- a/src/Symfony/Component/Messenger/Command/SetupTransportsCommand.php +++ b/src/Symfony/Component/Messenger/Command/SetupTransportsCommand.php @@ -71,11 +71,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int foreach ($transportNames as $id => $transportName) { $transport = $this->transportLocator->get($transportName); - if ($transport instanceof SetupableTransportInterface) { + if (!$transport instanceof SetupableTransportInterface) { + $io->note(sprintf('The "%s" transport does not support setup.', $transportName)); + continue; + } + + try { $transport->setup(); $io->success(sprintf('The "%s" transport was set up successfully.', $transportName)); - } else { - $io->note(sprintf('The "%s" transport does not support setup.', $transportName)); + } catch (\Exception $e) { + throw new \RuntimeException(sprintf('An error occurred while setting up the "%s" transport: ', $transportName).$e->getMessage(), 0, $e); } } diff --git a/src/Symfony/Component/Messenger/Tests/Command/SetupTransportsCommandTest.php b/src/Symfony/Component/Messenger/Tests/Command/SetupTransportsCommandTest.php index cfe9eca20b40..a260d41cb704 100644 --- a/src/Symfony/Component/Messenger/Tests/Command/SetupTransportsCommandTest.php +++ b/src/Symfony/Component/Messenger/Tests/Command/SetupTransportsCommandTest.php @@ -72,8 +72,6 @@ public function testReceiverNameArgument() public function testReceiverNameArgumentNotFound() { - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('The "not_found" transport does not exist.'); // mock a service locator /** @var MockObject&ServiceLocator $serviceLocator */ $serviceLocator = $this->createMock(ServiceLocator::class); @@ -86,9 +84,40 @@ public function testReceiverNameArgumentNotFound() $command = new SetupTransportsCommand($serviceLocator, ['amqp', 'other_transport']); $tester = new CommandTester($command); + + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('The "not_found" transport does not exist.'); $tester->execute(['transport' => 'not_found']); } + public function testThrowsExceptionOnTransportSetup() + { + // mock a setupable-transport, that throws + $amqpTransport = $this->createMock(SetupableTransportInterface::class); + $amqpTransport->expects($this->exactly(1)) + ->method('setup') + ->willThrowException(new \RuntimeException('Server not found')); + + // mock a service locator + /** @var MockObject&ServiceLocator $serviceLocator */ + $serviceLocator = $this->createMock(ServiceLocator::class); + $serviceLocator->expects($this->exactly(1)) + ->method('get') + ->will($this->onConsecutiveCalls( + $amqpTransport + )); + $serviceLocator + ->method('has') + ->willReturn(true); + + $command = new SetupTransportsCommand($serviceLocator, ['amqp']); + $tester = new CommandTester($command); + + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('An error occurred while setting up the "amqp" transport: Server not found'); + $tester->execute(['transport' => 'amqp']); + } + /** * @dataProvider provideCompletionSuggestions */
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: