Skip to content

Commit 8f1698f

Browse files
committed
Allow to disable lock without defining a resource
1 parent 187eb2a commit 8f1698f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

DependencyInjection/Configuration.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -1117,12 +1117,15 @@ private function addLockSection(ArrayNodeDefinition $rootNode)
11171117
})
11181118
->end()
11191119
->addDefaultsIfNotSet()
1120+
->validate()
1121+
->ifTrue(static function (array $config) { return $config['enabled'] && !$config['resources']; })
1122+
->thenInvalid('At least one resource must be defined.')
1123+
->end()
11201124
->fixXmlConfig('resource')
11211125
->children()
11221126
->arrayNode('resources')
11231127
->normalizeKeys(false)
11241128
->useAttributeAsKey('name')
1125-
->requiresAtLeastOneElement()
11261129
->defaultValue(['default' => [class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphore' : 'flock']])
11271130
->beforeNormalization()
11281131
->ifString()->then(function ($v) { return ['default' => $v]; })

Tests/DependencyInjection/ConfigurationTest.php

+25
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,31 @@ public function testItErrorsWhenDefaultBusDoesNotExist()
378378
]);
379379
}
380380

381+
public function testLockCanBeDisabled()
382+
{
383+
$processor = new Processor();
384+
$configuration = new Configuration(true);
385+
386+
$config = $processor->processConfiguration($configuration, [
387+
['lock' => ['enabled' => false]],
388+
]);
389+
390+
$this->assertFalse($config['lock']['enabled']);
391+
}
392+
393+
public function testEnabledLockNeedsResources()
394+
{
395+
$processor = new Processor();
396+
$configuration = new Configuration(true);
397+
398+
$this->expectException(InvalidConfigurationException::class);
399+
$this->expectExceptionMessage('Invalid configuration for path "framework.lock": At least one resource must be defined.');
400+
401+
$processor->processConfiguration($configuration, [
402+
['lock' => ['enabled' => true]],
403+
]);
404+
}
405+
381406
protected static function getBundleDefaultConfig()
382407
{
383408
return [

0 commit comments

Comments
 (0)