diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 3875db646ff21..3cef369a44347 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -1117,12 +1117,15 @@ private function addLockSection(ArrayNodeDefinition $rootNode) }) ->end() ->addDefaultsIfNotSet() + ->validate() + ->ifTrue(static function (array $config) { return $config['enabled'] && !$config['resources']; }) + ->thenInvalid('At least one resource must be defined.') + ->end() ->fixXmlConfig('resource') ->children() ->arrayNode('resources') ->normalizeKeys(false) ->useAttributeAsKey('name') - ->requiresAtLeastOneElement() ->defaultValue(['default' => [class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphore' : 'flock']]) ->beforeNormalization() ->ifString()->then(function ($v) { return ['default' => $v]; }) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index e4d36c522fbf2..861e161f6792d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -378,6 +378,31 @@ public function testItErrorsWhenDefaultBusDoesNotExist() ]); } + public function testLockCanBeDisabled() + { + $processor = new Processor(); + $configuration = new Configuration(true); + + $config = $processor->processConfiguration($configuration, [ + ['lock' => ['enabled' => false]], + ]); + + $this->assertFalse($config['lock']['enabled']); + } + + public function testEnabledLockNeedsResources() + { + $processor = new Processor(); + $configuration = new Configuration(true); + + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessage('Invalid configuration for path "framework.lock": At least one resource must be defined.'); + + $processor->processConfiguration($configuration, [ + ['lock' => ['enabled' => true]], + ]); + } + protected static function getBundleDefaultConfig() { return [