bug #39686 [Lock] Fix config merging in lock (jderusse)

This PR was merged into the 4.4 branch.

Discussion
----------

[Lock] Fix config merging in lock

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #35920
| License       | MIT
| Doc PR        | -

Commits
-------

6bb2d67cf1 Fix config merging in lock
This commit is contained in:
Fabien Potencier 2021-01-03 09:18:23 +01:00
commit a0d66d2ecd
2 changed files with 31 additions and 0 deletions

View File

@ -1122,6 +1122,8 @@ class Configuration implements ConfigurationInterface
->fixXmlConfig('resource')
->children()
->arrayNode('resources')
->normalizeKeys(false)
->useAttributeAsKey('name')
->requiresAtLeastOneElement()
->defaultValue(['default' => [class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphore' : 'flock']])
->beforeNormalization()
@ -1144,6 +1146,7 @@ class Configuration implements ConfigurationInterface
})
->end()
->prototype('array')
->performNoDeepMerging()
->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()
->prototype('scalar')->end()
->end()

View File

@ -250,6 +250,34 @@ class ConfigurationTest extends TestCase
yield [['enabled' => false, 'resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'foo', 'value' => 'semaphore'], ['name' => 'bar', 'value' => 'semaphore']]], ['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
}
public function testLockMergeConfigs()
{
$processor = new Processor();
$configuration = new Configuration(true);
$config = $processor->processConfiguration($configuration, [
[
'lock' => [
'payload' => 'flock',
],
],
[
'lock' => [
'payload' => 'semaphore'
],
],
]);
$this->assertEquals(
[
'enabled' => true,
'resources' => [
'payload' => ['semaphore']
],
],
$config['lock']
);
}
public function testItShowANiceMessageIfTwoMessengerBusesAreConfiguredButNoDefaultBus()
{
$expectedMessage = 'You must specify the "default_bus" if you define more than one bus.';