8000 feature #49044 [Messenger] Mention the transport which failed during … · symfony/symfony@8ac7385 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8ac7385

Browse files
committed
feature #49044 [Messenger] Mention the transport which failed during the setup command (thePanz)
This PR was merged into the 6.4 branch. Discussion ---------- [Messenger] Mention the transport which failed during the setup command The transport name can help to further investigate the underlying reasons of the failure | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | none | License | MIT | Doc PR | - I am not sure if this can be labelled as a new feature, but the addition from this PR can help to further investigate errors while setting up an application's transports. At the moment, if an error occurs while setting up a transport just the exception is thrown, with no context on which transport was being setup. Commits ------- 49c0af9 [Messenger] Mention the transport which failed during the setup command
2 parents 204381b + 49c0af9 commit 8ac7385

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7474

7575
foreach ($transportNames as $id => $transportName) {
7676
$transport = $this->transportLocator->get($transportName);
77-
if ($transport instanceof SetupableTransportInterface) {
77+
if (!$transport instanceof SetupableTransportInterface) {
78+
$io->note(sprintf('The "%s" transport does not support setup.', $transportName));
79+
continue;
80+
}
81+
82+
try {
7883
$transport->setup();
7984
$io->success(sprintf('The "%s" transport was set up successfully.', $transportName));
80-
} else {
81-
$io->note(sprintf('The "%s" transport does not support setup.', $transportName));
85+
} catch (\Exception $e) {
86+
throw new \RuntimeException(sprintf('An error occurred while setting up the "%s" transport: ', $transportName).$e->getMessage(), 0, $e);
8287
}
8388
}
8489

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

+31-2
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