From 36f16e8461290ec24888647ea7bb58759acdab5c Mon Sep 17 00:00:00 2001 From: Vincent Touzet Date: Tue, 28 May 2019 21:17:30 +0200 Subject: [PATCH] [FrameworkBundle] Add a validation on the messenger section --- .../DependencyInjection/Configuration.php | 4 +++ .../DependencyInjection/ConfigurationTest.php | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 44ed8213e916d..ea64157fde9bc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -1110,6 +1110,10 @@ private function addMessengerSection(ArrayNodeDefinition $rootNode) ->{!class_exists(FullStack::class) && interface_exists(MessageBusInterface::class) ? 'canBeDisabled' : 'canBeEnabled'}() ->fixXmlConfig('transport') ->fixXmlConfig('bus', 'buses') + ->validate() + ->ifTrue(function ($v) { return isset($v['buses']) && \count($v['buses']) > 1 && null === $v['default_bus']; }) + ->thenInvalid('You must specify the "default_bus" if you define more than one bus.') + ->end() ->children() ->arrayNode('routing') ->useAttributeAsKey('message_class') diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 79ebadef28439..3980036006b11 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -188,6 +188,31 @@ public function provideInvalidAssetConfigurationTests() yield [$createPackageConfig($config), 'You cannot use both "version" and "json_manifest_path" at the same time under "assets" packages.']; } + public function testItShowANiceMessageIfTwoMessengerBusesAreConfiguredButNoDefaultBus() + { + $expectedMessage = 'You must specify the "default_bus" if you define more than one bus.'; + if (method_exists($this, 'expectException')) { + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessage($expectedMessage); + } else { + $this->setExpectedException(InvalidConfigurationException::class, $expectedMessage); + } + $processor = new Processor(); + $configuration = new Configuration(true); + + $processor->processConfiguration($configuration, [ + 'framework' => [ + 'messenger' => [ + 'default_bus' => null, + 'buses' => [ + 'first_bus' => [], + 'second_bus' => [], + ], + ], + ], + ]); + } + protected static function getBundleDefaultConfig() { return [