8000 [Messenger] Mention the transport which failed during the setup command · symfony/symfony@49c0af9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 49c0af9

Browse files
committed
[Messenger] Mention the transport which failed during the setup command
The transport name can help to further investigate the underlying reasons of the failure
1 parent f06554b commit 49c0af9

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7171

7272
foreach ($transportNames as $id => $transportName) {
7373
$transport = $this->transportLocator->get($transportName);
74-
if ($transport instanceof SetupableTransportInterface) {
74+
if (!$transport instanceof SetupableTransportInterface) {
75+
$io->note(sprintf('The "%s" transport does not support setup.', $transportName));
76+
continue;
77+
}
78+
79+
try {
7580
$transport->setup();
7681
$io->success(sprintf('The "%s" transport was set up successfully.', $transportName));
77-
} else {
78-
$io->note(sprintf('The "%s" transport does not support setup.', $transportName));
82+
} catch (\Exception $e) {
83+
throw new \RuntimeException(sprintf('An error occurred while setting up the "%s" transport: ', $transportName).$e->getMessage(), 0, $e);
7984
}
8085
}
8186

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ public function testReceiverNameArgument()
7272

7373
public function testReceiverNameArgumentNotFound()
7474
{
75-
$this->expectException(\RuntimeException::class);
76-
$this->expectExceptionMessage('The "not_found" transport does not exist.');
7775
// mock a service locator
7876
/** @var MockObject&ServiceLocator $serviceLocator */
7977
$serviceLocator = $this->createMock(ServiceLocator::class);
@@ -86,9 +84,40 @@ public function testReceiverNameArgumentNotFound()
8684

8785
$command = new SetupTransportsCommand($serviceLocator, ['amqp', 'other_transport']);
8886
$tester = new CommandTester($command);
87+
88+
$this->expectException(\RuntimeException::class);
89+
$this->expectExceptionMessage('The "not_found" transport does not exist.');
8990
$tester->execute(['transport' => 'not_found']);
9091
}
9192

93+
public function testThrowsExceptionOnTransportSetup()
94+
{
95+
// mock a setupable-transport, that throws
96+
$amqpTransport = $this->createMock(SetupableTransportInterface::class);
97+
$amqpTransport->expects($this->exactly(1))
98+
->method('setup')
99+
->willThrowException(new \RuntimeException('Server not found'));
100+
101+
// mock a service locator
102+
/** @var MockObject&ServiceLocator $serviceLocator */
103+
$serviceLocator = $this->createMock(ServiceLocator::class);
104+
$serviceLocator->expects($this->exactly(1))
105+
->method('get')
106+
->will($this->onConsecutiveCalls(
107+
$amqpTransport
108+
));
109+
$serviceLocator
110+
->method('has')
111+
->willReturn(true);
112+
113+
$command = new SetupTransportsCommand($serviceLocator, ['amqp']);
114+
$tester = new CommandTester($command);
115+
116+
$this->expectException(\RuntimeException::class);
117+
$this->expectExceptionMessage('An error occurred while setting up the "amqp" transport: Server not found');
118+
$tester->execute(['transport' => 'amqp']);
119+
}
120+
92121
/**
93122
* @dataProvider provideCompletionSuggestions
94123
*/

0 commit comments

Comments
 (0)
0