8000 minor #31662 [FrameworkBundle] Add a validation on the messenger sect… · symfony/symfony@e1923c6 · GitHub
[go: up one dir, main page]

Skip to content

Commit e1923c6

Browse files
committed
minor #31662 [FrameworkBundle] Add a validation on the messenger section (vincenttouzet)
This PR was merged into the 4.3 branch. Discussion ---------- [FrameworkBundle] Add a validation on the messenger section | Q | A | ------------- | --- | Branch? | 4.3 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no | Tests pass? | yes | Fixed tickets | #31624 <!-- #-prefixed issue number(s), if any --> | License | MIT <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/roadmap): - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. --> Commits ------- 36f16e8 [FrameworkBundle] Add a validation on the messenger section
2 parents ac88953 + 36f16e8 commit e1923c6

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,10 @@ private function addMessengerSection(ArrayNodeDefinition $rootNode)
11101110
->{!class_exists(FullStack::class) && interface_exists(MessageBusInterface::class) ? 'canBeDisabled' : 'canBeEnabled'}()
11111111
->fixXmlConfig('transport')
11121112
->fixXmlConfig('bus', 'buses')
1113+
->validate()
1114+
->ifTrue(function ($v) { return isset($v['buses']) && \count($v['buses']) > 1 && null === $v['default_bus']; })
1115+
->thenInvalid('You must specify the "default_bus" if you define more than one bus.')
1116+
->end()
11131117
->children()
11141118
->arrayNode('routing')
11151119
->useAttributeAsKey('message_class')

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,31 @@ public function provideInvalidAssetConfigurationTests()
188188
yield [$createPackageConfig($config), 'You cannot use both "version" and "json_manifest_path" at the same time under "assets" packages.'];
189189
}
190190

191+
public function testItShowANiceMessageIfTwoMessengerBusesAreConfiguredButNoDefaultBus()
192+
{
193+
$expectedMessage = 'You must specify the "default_bus" if you define more than one bus.';
194+
if (method_exists($this, 'expectException')) {
195+
$this->expectException(InvalidConfigurationException::class);
196+
$this->expectExceptionMessage($expectedMessage);
197+
} else {
198+
$this->setExpectedException(InvalidConfigurationException::class, $expectedMessage);
199+
}
200+
$processor = new Processor();
201+
$configuration = new Configuration(true);
202+
203+
$processor->processConfiguration($configuration, [
204+
'framework' => [
205+
'messenger' => [
206+
'default_bus' => null,
207+
'buses' => [
208+
'first_bus' => [],
209+
'second_bus' => [],
210+
],
211+
],
212+
],
213+
]);
214+
}
215+
191216
protected static function getBundleDefaultConfig()
192217
{
193218
return [

0 commit comments

Comments
 (0)
0