Skip to content

Commit b402f2d

Browse files
Merge branch '4.3' into 4.4
* 4.3: [FrameworkBundle] Fix framework bundle lock configuration not working as expected [Validator] Add the missing translations for the Azerbaijani locale [HttpClient] workaround bad Content-Length sent by old libcurl [Cache] dont override native Memcached options Fix CS Fix exceptions (PDOException) error code type Fix return type of Process::restart(). [Cache] fail gracefully when locking is not supported [HttpClient] fix race condition when reading response with informational status Names for buttons should start with lowercase
2 parents 08ed30c + d58c9f7 commit b402f2d

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

DependencyInjection/Configuration.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,11 @@ private function addLockSection(ArrayNodeDefinition $rootNode)
10741074
->ifString()->then(function ($v) { return ['enabled' => true, 'resources' => $v]; })
10751075
->end()
10761076
->beforeNormalization()
1077-
->ifTrue(function ($v) { return \is_array($v) && !isset($v['resources']); })
1077+
->ifTrue(function ($v) { return \is_array($v) && !isset($v['enabled']); })
1078+
->then(function ($v) { return $v + ['enabled' => true]; })
1079+
->end()
1080+
->beforeNormalization()
1081+
->ifTrue(function ($v) { return \is_array($v) && !isset($v['resources']) && !isset($v['resource']); })
10781082
->then(function ($v) {
10791083
$e = $v['enabled'];
10801084
unset($v['enabled']);
@@ -1093,7 +1097,19 @@ private function addLockSection(ArrayNodeDefinition $rootNode)
10931097
->end()
10941098
->beforeNormalization()
10951099
->ifTrue(function ($v) { return \is_array($v) && array_keys($v) === range(0, \count($v) - 1); })
1096-
->then(function ($v) { return ['default' => $v]; })
1100+
->then(function ($v) {
1101+
$resources = [];
1102+
foreach ($v as $resource) {
1103+
$resources = array_merge_recursive(
1104+
$resources,
1105+
\is_array($resource) && isset($resource['name'])
1106+
? [$resource['name'] => $resource['value']]
1107+
: ['default' => $resource]
1108+
);
1109+
}
1110+
1111+
return $resources;
1112+
})
10971113
->end()
10981114
->prototype('array')
10991115
->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,69 @@ public function provideInvalidAssetConfigurationTests()
187187
yield [$createPackageConfig($config), 'You cannot use both "version" and "json_manifest_path" at the same time under "assets" packages.'];
188188
}
189189

190+
/**
191+
* @dataProvider provideValidLockConfigurationTests
192+
*/
193+
public function testValidLockConfiguration($lockConfig, $processedConfig)
194+
{
195+
$processor = new Processor();
196+
$configuration = new Configuration(true);
197+
$config = $processor->processConfiguration($configuration, [
198+
[
199+
'lock' => $lockConfig,
200+
],
201+
]);
202+
203+
$this->assertArrayHasKey('lock', $config);
204+
205+
$this->assertEquals($processedConfig, $config['lock']);
206+
}
207+
208+
public function provideValidLockConfigurationTests()
209+
{
210+
yield [null, ['enabled' => true, 'resources' => ['default' => [class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphore' : 'flock']]]];
211+
212+
yield ['flock', ['enabled' => true, 'resources' => ['default' => ['flock']]]];
213+
yield [['flock', 'semaphore'], ['enabled' => true, 'resources' => ['default' => ['flock', 'semaphore']]]];
214+
yield [['foo' => 'flock', 'bar' => 'semaphore'], ['enabled' => true, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
215+
yield [['foo' => ['flock', 'semaphore'], 'bar' => 'semaphore'], ['enabled' => true, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
216+
yield [['default' => 'flock'], ['enabled' => true, 'resources' => ['default' => ['flock']]]];
217+
218+
yield [['enabled' => false, 'flock'], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
219+
yield [['enabled' => false, ['flock', 'semaphore']], ['enabled' => false, 'resources' => ['default' => ['flock', 'semaphore']]]];
220+
yield [['enabled' => false, 'foo' => 'flock', 'bar' => 'semaphore'], ['enabled' => false, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
221+
yield [['enabled' => false, 'foo' => ['flock', 'semaphore']], ['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore']]]];
222+
yield [['enabled' => false, 'default' => 'flock'], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
223+
224+
yield [['resources' => 'flock'], ['enabled' => true, 'resources' => ['default' => ['flock']]]];
225+
yield [['resources' => ['flock', 'semaphore']], ['enabled' => true, 'resources' => ['default' => ['flock', 'semaphore']]]];
226+
yield [['resources' => ['foo' => 'flock', 'bar' => 'semaphore']], ['enabled' => true, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
227+
yield [['resources' => ['foo' => ['flock', 'semaphore'], 'bar' => 'semaphore']], ['enabled' => true, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
228+
yield [['resources' => ['default' => 'flock']], ['enabled' => true, 'resources' => ['default' => ['flock']]]];
229+
230+
yield [['enabled' => false, 'resources' => 'flock'], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
231+
yield [['enabled' => false, 'resources' => ['flock', 'semaphore']], ['enabled' => false, 'resources' => ['default' => ['flock', 'semaphore']]]];
232+
yield [['enabled' => false, 'resources' => ['foo' => 'flock', 'bar' => 'semaphore']], ['enabled' => false, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
233+
yield [['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => 'semaphore']], ['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
234+
yield [['enabled' => false, 'resources' => ['default' => 'flock']], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
235+
236+
// xml
237+
238+
yield [['resource' => ['flock']], ['enabled' => true, 'resources' => ['default' => ['flock']]]];
239+
yield [['resource' => ['flock', ['name' => 'foo', 'value' => 'semaphore']]], ['enabled' => true, 'resources' => ['default' => ['flock'], 'foo' => ['semaphore']]]];
240+
yield [['resource' => [['name' => 'foo', 'value' => 'flock']]], ['enabled' => true, 'resources' => ['foo' => ['flock']]]];
241+
yield [['resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'foo', 'value' => 'semaphore']]], ['enabled' => true, 'resources' => ['foo' => ['flock', 'semaphore']]]];
242+
yield [['resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'bar', 'value' => 'semaphore']]], ['enabled' => true, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
243+
yield [['resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'foo', 'value' => 'semaphore'], ['name' => 'bar', 'value' => 'semaphore']]], ['enabled' => true, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
244+
245+
yield [['enabled' => false, 'resource' => ['flock']], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
246+
yield [['enabled' => false, 'resource' => ['flock', ['name' => 'foo', 'value' => 'semaphore']]], ['enabled' => false, 'resources' => ['default' => ['flock'], 'foo' => ['semaphore']]]];
247+
yield [['enabled' => false, 'resource' => [['name' => 'foo', 'value' => 'flock']]], ['enabled' => false, 'resources' => ['foo' => ['flock']]]];
248+
yield [['enabled' => false, 'resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'foo', 'value' => 'semaphore']]], ['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore']]]];
249+
yield [['enabled' => false, 'resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'bar', 'value' => 'semaphore']]], ['enabled' => false, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
250+
yield [['enabled' => false, 'resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'foo', 'value' => 'semaphore'], ['name' => 'bar', 'value' => 'semaphore']]], ['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
251+
}
252+
190253
public function testItShowANiceMessageIfTwoMessengerBusesAreConfiguredButNoDefaultBus()
191254
{
192255
$expectedMessage = 'You must specify the "default_bus" if you define more than one bus.';

0 commit comments

Comments
 (0)