8000 [Messenger] Mention the transport which failed during the setup command by thePanz · Pull Request #49044 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Messenger] Mention the transport which failed during the setup command #49044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
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