8000 bug #34547 [Messenger] Error when specified default bus is not among … · symfony/symfony@08489ce · GitHub
[go: up one dir, main page]

Skip to content

Commit 08489ce

Browse files
committed
bug #34547 [Messenger] Error when specified default bus is not among the configured (vudaltsov)
This PR was squashed before being merged into the 4.3 branch (closes #34547). Discussion ---------- [Messenger] Error when specified default bus is not among the configured | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | n/a | License | MIT | Doc PR | n/a This is a bug fix because the error occurs during the di compilation anyway. Commits ------- dd92d2b [Messenger] Error when specified default bus is not among the configured
2 parents 32e1be8 + dd92d2b commit 08489ce

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
2020
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
2121
use Symfony\Component\Config\Definition\ConfigurationInterface;
22+
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
2223
use Symfony\Component\DependencyInjection\Exception\LogicException;
2324
use Symfony\Component\Form\Form;
2425
use Symfony\Component\HttpClient\HttpClient;
@@ -1136,6 +1137,10 @@ private function addMessengerSection(ArrayNodeDefinition $rootNode)
11361137
->ifTrue(function ($v) { return isset($v['buses']) && \count($v['buses']) > 1 && null === $v['default_bus']; })
11371138
->thenInvalid('You must specify the "default_bus" if you define more than one bus.')
11381139
->end()
1140+
->validate()
1141+
->ifTrue(static function ($v): bool { return isset($v['buses']) && null !== $v['default_bus'] && !isset($v['buses'][$v['default_bus']]); })
1142+
->then(static function (array $v): void { throw new InvalidConfigurationException(sprintf('The specified default bus "%s" is not configured. Available buses are "%s".', $v['default_bus'], implode('", "', array_keys($v['buses'])))); })
1143+
->end()
11391144
->children()
11401145
->arrayNode('routing')
11411146
->normalizeKeys(false)

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,27 @@ public functi 8000 on testItShowANiceMessageIfTwoMessengerBusesAreConfiguredButNoDefau
271271
]);
272272
}
273273

274+
public function testItErrorsWhenDefaultBusDoesNotExist()
275+
{
276+
$processor = new Processor();
277+
$configuration = new Configuration(true);
278+
279+
$this->expectException(InvalidConfigurationException::class);
280+
$this->expectExceptionMessage('The specified default bus "foo" is not configured. Available buses are "bar", "baz".');
281+
282+
$processor->processConfiguration($configuration, [
283+
[
284+
'messenger' => [
285+
'default_bus' => 'foo',
286+
'buses' => [
287+
'bar' => null,
288+
'baz' => null,
289+
],
290+
],
291+
],
292+
]);
293+
}
294+
274295
protected static function getBundleDefaultConfig()
275296
{
276297
return [

0 commit comments

Comments
 (0)
0