Skip to content

Commit 0f79059

Browse files
committed
Merge remote-tracking branch 'local/ACP2E-1604' into PR_7_JAN_2023
2 parents 9e630ef + e124d65 commit 0f79059

File tree

2 files changed

+100
-3
lines changed

2 files changed

+100
-3
lines changed

setup/src/Magento/Setup/Model/ConfigOptionsList/Lock.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,10 @@ private function setDefaultConfiguration(
316316
string $lockProvider
317317
) {
318318
foreach ($this->mappingInputKeyToConfigPath[$lockProvider] as $input => $path) {
319-
// do not set default value null for lock db prefix
320-
if ($input !== self::INPUT_KEY_LOCK_DB_PREFIX) {
321-
$configData->set($path, $deploymentConfig->get($path, $this->getDefaultValue($input)));
319+
// do not set default value null for lock db prefix, but save current value if it exists
320+
$defaultValue = $deploymentConfig->get($path, $this->getDefaultValue($input));
321+
if (($input !== self::INPUT_KEY_LOCK_DB_PREFIX) || ($defaultValue !== null)) {
322+
$configData->set($path, $defaultValue);
322323
}
323324
}
324325

setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsList/LockTest.php

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,102 @@ public function createConfigDataProvider(): array
194194
];
195195
}
196196

197+
/**
198+
* @param array $options
199+
* @param array $expectedResult
200+
* @dataProvider updateConfigDataProvider
201+
*/
202+
public function testUpdateConfig(array $options, array $expectedResult)
203+
{
204+
$valueMap = [
205+
[ 'lock/config/prefix', null, 'saved_prefix' ],
206+
[ 'lock/provider', 'db', 'db' ]
207+
];
208+
$this->deploymentConfigMock
209+
->expects($this->any())
210+
->method('get')
211+
->willReturnMap($valueMap);
212+
$data = $this->lockConfigOptionsList->createConfig($options, $this->deploymentConfigMock);
213+
$this->assertInstanceOf(ConfigData::class, $data);
214+
$this->assertTrue($data->isOverrideWhenSave());
215+
$this->assertSame($expectedResult, $data->getData());
216+
}
217+
218+
/**
219+
* @return array
220+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
221+
*/
222+
public function updateConfigDataProvider(): array
223+
{
224+
return [
225+
'Check existent value for lock-db-prefix is not erased with no parameter specified' => [
226+
'options' => [],
227+
'expectedResult' => [
228+
'lock' => [
229+
'provider' => LockBackendFactory::LOCK_DB,
230+
'config' => [
231+
'prefix' => 'saved_prefix',
232+
],
233+
],
234+
],
235+
],
236+
'Check lock-db-prefix options overrides existing value when parameter is specified' => [
237+
'options' => [
238+
LockConfigOptionsList::INPUT_KEY_LOCK_PROVIDER => LockBackendFactory::LOCK_DB,
239+
LockConfigOptionsList::INPUT_KEY_LOCK_DB_PREFIX => 'new_prefix'
240+
],
241+
'expectedResult' => [
242+
'lock' => [
243+
'provider' => LockBackendFactory::LOCK_DB,
244+
'config' => [
245+
'prefix' => 'new_prefix',
246+
],
247+
],
248+
],
249+
],
250+
'Check lock-db-prefix options overrides existing value when only this parameter is specified' => [
251+
'options' => [
252+
LockConfigOptionsList::INPUT_KEY_LOCK_DB_PREFIX => 'new_prefix'
253+
],
254+
'expectedResult' => [
255+
'lock' => [
256+
'provider' => LockBackendFactory::LOCK_DB,
257+
'config' => [
258+
'prefix' => 'new_prefix',
259+
],
260+
],
261+
],
262+
],
263+
'Check that lock-db-prefix value is not erased when when only lock-provider is specified as db' => [
264+
'options' => [
265+
LockConfigOptionsList::INPUT_KEY_LOCK_PROVIDER => LockBackendFactory::LOCK_DB,
266+
],
267+
'expectedResult' => [
268+
'lock' => [
269+
'provider' => LockBackendFactory::LOCK_DB,
270+
'config' => [
271+
'prefix' => 'saved_prefix',
272+
],
273+
],
274+
],
275+
],
276+
'Check specific db lock prefix empty options overrides existing value' => [
277+
'options' => [
278+
LockConfigOptionsList::INPUT_KEY_LOCK_PROVIDER => LockBackendFactory::LOCK_DB,
279+
LockConfigOptionsList::INPUT_KEY_LOCK_DB_PREFIX => ''
280+
],
281+
'expectedResult' => [
282+
'lock' => [
283+
'provider' => LockBackendFactory::LOCK_DB,
284+
'config' => [
285+
'prefix' => '',
286+
],
287+
],
288+
],
289+
],
290+
];
291+
}
292+
197293
/**
198294
* @param array $options
199295
* @param array $expectedResult

0 commit comments

Comments
 (0)