From aaf2be4c3d47395155bdd7c508efc14a54dee512 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 14 Jul 2016 15:09:47 +0200 Subject: [PATCH] Use argument instead of value --- core/Command/User/Setting.php | 24 ++++++++-------- tests/Core/Command/User/SettingTest.php | 38 ++++++++++++------------- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/core/Command/User/Setting.php b/core/Command/User/Setting.php index 0a1ca1990a7..7a62b5529b3 100644 --- a/core/Command/User/Setting.php +++ b/core/Command/User/Setting.php @@ -90,11 +90,11 @@ class Setting extends Base { ) // Set - ->addOption( + ->addArgument( 'value', - null, - InputOption::VALUE_REQUIRED, - 'The new value of the setting' + InputArgument::OPTIONAL, + 'The new value of the setting', + null ) ->addOption( 'update-only', @@ -129,13 +129,13 @@ class Setting extends Base { throw new \InvalidArgumentException('The "default-value" option can only be used when specifying a key.'); } - if ($input->getArgument('key') === '' && $input->hasParameterOption('--value')) { - throw new \InvalidArgumentException('The "value" option can only be used when specifying a key.'); + if ($input->getArgument('key') === '' && $input->getArgument('value') !== null) { + throw new \InvalidArgumentException('The value argument can only be used when specifying a key.'); } - if ($input->hasParameterOption('--value') && $input->hasParameterOption('--default-value')) { - throw new \InvalidArgumentException('The "value" option can not be used together with "default-value".'); + if ($input->getArgument('value') !== null && $input->hasParameterOption('--default-value')) { + throw new \InvalidArgumentException('The value argument can not be used together with "default-value".'); } - if ($input->getOption('update-only') && !$input->hasParameterOption('--value')) { + if ($input->getOption('update-only') && $input->getArgument('value') === null) { throw new \InvalidArgumentException('The "update-only" option can only be used together with "value".'); } @@ -145,7 +145,7 @@ class Setting extends Base { if ($input->getOption('delete') && $input->hasParameterOption('--default-value')) { throw new \InvalidArgumentException('The "delete" option can not be used together with "default-value".'); } - if ($input->getOption('delete') && $input->hasParameterOption('--value')) { + if ($input->getOption('delete') && $input->getArgument('value') !== null) { throw new \InvalidArgumentException('The "delete" option can not be used together with "value".'); } if ($input->getOption('error-if-not-exists') && !$input->getOption('delete')) { @@ -167,13 +167,13 @@ class Setting extends Base { if ($key !== '') { $value = $this->config->getUserValue($uid, $app, $key, null); - if ($input->hasParameterOption('--value')) { + if ($input->getArgument('value') !== null) { if ($input->hasParameterOption('--update-only') && $value === null) { $output->writeln('The setting does not exist for user "' . $uid . '".'); return 1; } - $this->config->setUserValue($uid, $app, $key, $input->getOption('value')); + $this->config->setUserValue($uid, $app, $key, $input->getArgument('value')); return 0; } else if ($input->hasParameterOption('--delete')) { diff --git a/tests/Core/Command/User/SettingTest.php b/tests/Core/Command/User/SettingTest.php index b05ee42d2dd..002e8dfef2f 100644 --- a/tests/Core/Command/User/SettingTest.php +++ b/tests/Core/Command/User/SettingTest.php @@ -107,37 +107,37 @@ class SettingTest extends TestCase { ], [ - [['uid', 'username'], ['key', 'configkey']], + [['uid', 'username'], ['key', 'configkey'], ['value', '']], [['ignore-missing-user', true]], - [['--value', true]], + [], false, false, ], [ - [['uid', 'username'], ['key', '']], + [['uid', 'username'], ['key', ''], ['value', '']], [['ignore-missing-user', true]], - [['--value', true]], + [], false, - 'The "value" option can only be used when specifying a key.', + 'The value argument can only be used when specifying a key.', ], [ - [['uid', 'username'], ['key', 'configkey']], + [['uid', 'username'], ['key', 'configkey'], ['value', '']], [['ignore-missing-user', true]], - [['--value', true], ['--default-value', true]], + [['--default-value', true]], false, - 'The "value" option can not be used together with "default-value".', + 'The value argument can not be used together with "default-value".', ], [ - [['uid', 'username'], ['key', 'configkey']], + [['uid', 'username'], ['key', 'configkey'], ['value', '']], [['ignore-missing-user', true], ['update-only', true]], - [['--value', true]], + [], false, false, ], [ - [['uid', 'username'], ['key', 'configkey']], + [['uid', 'username'], ['key', 'configkey'], ['value', null]], [['ignore-missing-user', true], ['update-only', true]], - [['--value', false]], + [], false, 'The "update-only" option can only be used together with "value".', ], @@ -164,9 +164,9 @@ class SettingTest extends TestCase { 'The "delete" option can not be used together with "default-value".', ], [ - [['uid', 'username'], ['key', 'configkey']], + [['uid', 'username'], ['key', 'configkey'], ['value', '']], [['ignore-missing-user', true], ['delete', true]], - [['--value', true]], + [], false, 'The "delete" option can not be used together with "value".', ], @@ -324,12 +324,13 @@ class SettingTest extends TestCase { 'getUserSettings', ]); - $this->consoleInput->expects($this->any()) + $this->consoleInput->expects($this->atLeast(4)) ->method('getArgument') ->willReturnMap([ ['uid', 'username'], ['app', 'appname'], ['key', 'configkey'], + ['value', 'setValue'], ]); $command->expects($this->once()) @@ -343,7 +344,6 @@ class SettingTest extends TestCase { $this->consoleInput->expects($this->atLeastOnce()) ->method('hasParameterOption') ->willReturnMap([ - ['--value', true], ['--update-only', $updateOnly], ]); @@ -351,10 +351,8 @@ class SettingTest extends TestCase { $this->consoleOutput->expects($this->never()) ->method('writeln'); - $this->consoleInput->expects($this->once()) - ->method('getOption') - ->with('value') - ->willReturn('setValue'); + $this->consoleInput->expects($this->never()) + ->method('getOption'); $this->config->expects($this->once()) ->method('setUserValue') -- 2.39.5