[FrameworkBundle] Fix framework bundle lock configuration not working as expected
This commit is contained in:
parent
287da8d4c0
commit
c7af2df340
@ -929,7 +929,11 @@ class Configuration implements ConfigurationInterface
|
||||
->ifString()->then(function ($v) { return ['enabled' => true, 'resources' => $v]; })
|
||||
->end()
|
||||
->beforeNormalization()
|
||||
->ifTrue(function ($v) { return \is_array($v) && !isset($v['resources']); })
|
||||
->ifTrue(function ($v) { return \is_array($v) && !isset($v['enabled']); })
|
||||
->then(function ($v) { return $v + ['enabled' => true]; })
|
||||
->end()
|
||||
->beforeNormalization()
|
||||
->ifTrue(function ($v) { return \is_array($v) && !isset($v['resources']) && !isset($v['resource']); })
|
||||
->then(function ($v) {
|
||||
$e = $v['enabled'];
|
||||
unset($v['enabled']);
|
||||
@ -948,7 +952,19 @@ class Configuration implements ConfigurationInterface
|
||||
->end()
|
||||
->beforeNormalization()
|
||||
->ifTrue(function ($v) { return \is_array($v) && array_keys($v) === range(0, \count($v) - 1); })
|
||||
->then(function ($v) { return ['default' => $v]; })
|
||||
->then(function ($v) {
|
||||
$resources = [];
|
||||
foreach ($v as $resource) {
|
||||
$resources = array_merge_recursive(
|
||||
$resources,
|
||||
\is_array($resource) && isset($resource['name'])
|
||||
? [$resource['name'] => $resource['value']]
|
||||
: ['default' => $resource]
|
||||
);
|
||||
}
|
||||
|
||||
return $resources;
|
||||
})
|
||||
->end()
|
||||
->prototype('array')
|
||||
->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()
|
||||
|
@ -296,6 +296,69 @@ class ConfigurationTest extends TestCase
|
||||
yield [$createPackageConfig($config), 'You cannot use both "version" and "json_manifest_path" at the same time under "assets" packages.'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideValidLockConfigurationTests
|
||||
*/
|
||||
public function testValidLockConfiguration($lockConfig, $processedConfig)
|
||||
{
|
||||
$processor = new Processor();
|
||||
$configuration = new Configuration(true);
|
||||
$config = $processor->processConfiguration($configuration, [
|
||||
[
|
||||
'lock' => $lockConfig,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertArrayHasKey('lock', $config);
|
||||
|
||||
$this->assertEquals($processedConfig, $config['lock']);
|
||||
}
|
||||
|
||||
public function provideValidLockConfigurationTests()
|
||||
{
|
||||
yield [null, ['enabled' => true, 'resources' => ['default' => [class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphore' : 'flock']]]];
|
||||
|
||||
yield ['flock', ['enabled' => true, 'resources' => ['default' => ['flock']]]];
|
||||
yield [['flock', 'semaphore'], ['enabled' => true, 'resources' => ['default' => ['flock', 'semaphore']]]];
|
||||
yield [['foo' => 'flock', 'bar' => 'semaphore'], ['enabled' => true, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
|
||||
yield [['foo' => ['flock', 'semaphore'], 'bar' => 'semaphore'], ['enabled' => true, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
|
||||
yield [['default' => 'flock'], ['enabled' => true, 'resources' => ['default' => ['flock']]]];
|
||||
|
||||
yield [['enabled' => false, 'flock'], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
|
||||
yield [['enabled' => false, ['flock', 'semaphore']], ['enabled' => false, 'resources' => ['default' => ['flock', 'semaphore']]]];
|
||||
yield [['enabled' => false, 'foo' => 'flock', 'bar' => 'semaphore'], ['enabled' => false, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
|
||||
yield [['enabled' => false, 'foo' => ['flock', 'semaphore']], ['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore']]]];
|
||||
yield [['enabled' => false, 'default' => 'flock'], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
|
||||
|
||||
yield [['resources' => 'flock'], ['enabled' => true, 'resources' => ['default' => ['flock']]]];
|
||||
yield [['resources' => ['flock', 'semaphore']], ['enabled' => true, 'resources' => ['default' => ['flock', 'semaphore']]]];
|
||||
yield [['resources' => ['foo' => 'flock', 'bar' => 'semaphore']], ['enabled' => true, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
|
||||
yield [['resources' => ['foo' => ['flock', 'semaphore'], 'bar' => 'semaphore']], ['enabled' => true, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
|
||||
yield [['resources' => ['default' => 'flock']], ['enabled' => true, 'resources' => ['default' => ['flock']]]];
|
||||
|
||||
yield [['enabled' => false, 'resources' => 'flock'], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
|
||||
yield [['enabled' => false, 'resources' => ['flock', 'semaphore']], ['enabled' => false, 'resources' => ['default' => ['flock', 'semaphore']]]];
|
||||
yield [['enabled' => false, 'resources' => ['foo' => 'flock', 'bar' => 'semaphore']], ['enabled' => false, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
|
||||
yield [['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => 'semaphore']], ['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
|
||||
yield [['enabled' => false, 'resources' => ['default' => 'flock']], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
|
||||
|
||||
// xml
|
||||
|
||||
yield [['resource' => ['flock']], ['enabled' => true, 'resources' => ['default' => ['flock']]]];
|
||||
yield [['resource' => ['flock', ['name' => 'foo', 'value' => 'semaphore']]], ['enabled' => true, 'resources' => ['default' => ['flock'], 'foo' => ['semaphore']]]];
|
||||
yield [['resource' => [['name' => 'foo', 'value' => 'flock']]], ['enabled' => true, 'resources' => ['foo' => ['flock']]]];
|
||||
yield [['resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'foo', 'value' => 'semaphore']]], ['enabled' => true, 'resources' => ['foo' => ['flock', 'semaphore']]]];
|
||||
yield [['resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'bar', 'value' => 'semaphore']]], ['enabled' => true, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
|
||||
yield [['resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'foo', 'value' => 'semaphore'], ['name' => 'bar', 'value' => 'semaphore']]], ['enabled' => true, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
|
||||
|
||||
yield [['enabled' => false, 'resource' => ['flock']], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
|
||||
yield [['enabled' => false, 'resource' => ['flock', ['name' => 'foo', 'value' => 'semaphore']]], ['enabled' => false, 'resources' => ['default' => ['flock'], 'foo' => ['semaphore']]]];
|
||||
yield [['enabled' => false, 'resource' => [['name' => 'foo', 'value' => 'flock']]], ['enabled' => false, 'resources' => ['foo' => ['flock']]]];
|
||||
yield [['enabled' => false, 'resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'foo', 'value' => 'semaphore']]], ['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore']]]];
|
||||
yield [['enabled' => false, 'resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'bar', 'value' => 'semaphore']]], ['enabled' => false, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
|
||||
yield [['enabled' => false, 'resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'foo', 'value' => 'semaphore'], ['name' => 'bar', 'value' => 'semaphore']]], ['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
|
||||
}
|
||||
|
||||
protected static function getBundleDefaultConfig()
|
||||
{
|
||||
return [
|
||||
|
Reference in New Issue
Block a user