Skip to content

Commit

Permalink
feature #49044 [Messenger] Mention the transport which failed during …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
fabpot committed Oct 6, 2023
2 parents 204381b + 49c0af9 commit 8ac7385
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
Expand Up @@ -74,11 +74,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);
}
}

Expand Down
Expand Up @@ -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);
Expand All @@ -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
*/
Expand Down

0 comments on commit 8ac7385

Please sign in to comment.