diff --git a/core/Command/Config/App/Base.php b/core/Command/Config/App/Base.php
index 7d3e9a831933c..07341c4faf931 100644
--- a/core/Command/Config/App/Base.php
+++ b/core/Command/Config/App/Base.php
@@ -1,15 +1,21 @@
appConfig->getApps();
}
if ($argumentName === 'name') {
$appName = $context->getWordAtIndex($context->getWordIndex() - 1);
- return $this->config->getAppKeys($appName);
+ return $this->appConfig->getKeys($appName);
}
return [];
}
diff --git a/core/Command/Config/App/DeleteConfig.php b/core/Command/Config/App/DeleteConfig.php
index 2e34197e5416b..5a08ecbdc4279 100644
--- a/core/Command/Config/App/DeleteConfig.php
+++ b/core/Command/Config/App/DeleteConfig.php
@@ -1,5 +1,6 @@
getArgument('app');
$configName = $input->getArgument('name');
- if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->config->getAppKeys($appName))) {
+ if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->appConfig->getKeys($appName), true)) {
$output->writeln('Config ' . $configName . ' of app ' . $appName . ' could not be deleted because it did not exist');
return 1;
}
- $this->config->deleteAppValue($appName, $configName);
+ $this->appConfig->deleteKey($appName, $configName);
$output->writeln('Config value ' . $configName . ' of app ' . $appName . ' deleted');
return 0;
}
diff --git a/core/Command/Config/App/GetConfig.php b/core/Command/Config/App/GetConfig.php
index 2fd632384a2f8..74a230ff5fc5e 100644
--- a/core/Command/Config/App/GetConfig.php
+++ b/core/Command/Config/App/GetConfig.php
@@ -9,19 +9,12 @@
namespace OC\Core\Command\Config\App;
use OCP\Exceptions\AppConfigUnknownKeyException;
-use OCP\IAppConfig;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class GetConfig extends Base {
- public function __construct(
- protected IAppConfig $appConfig,
- ) {
- parent::__construct();
- }
-
protected function configure() {
parent::configure();
diff --git a/core/Command/Config/App/SetConfig.php b/core/Command/Config/App/SetConfig.php
index 0484c2da84693..dc836d56cc43d 100644
--- a/core/Command/Config/App/SetConfig.php
+++ b/core/Command/Config/App/SetConfig.php
@@ -20,12 +20,6 @@
use Symfony\Component\Console\Question\Question;
class SetConfig extends Base {
- public function __construct(
- protected IAppConfig $appConfig,
- ) {
- parent::__construct();
- }
-
protected function configure() {
parent::configure();
diff --git a/tests/Core/Command/Config/App/DeleteConfigTest.php b/tests/Core/Command/Config/App/DeleteConfigTest.php
index 643c7ca3ca17c..1e44c2aafe62e 100644
--- a/tests/Core/Command/Config/App/DeleteConfigTest.php
+++ b/tests/Core/Command/Config/App/DeleteConfigTest.php
@@ -1,4 +1,6 @@
config = $this->getMockBuilder(IConfig::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
- $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
+ $this->appConfig = $this->createMock(IAppConfig::class);
+ $this->consoleInput = $this->createMock(InputInterface::class);
+ $this->consoleOutput = $this->createMock(OutputInterface::class);
- $this->command = new DeleteConfig($this->config);
+ $this->command = new DeleteConfig($this->appConfig);
}
- public function deleteData() {
+ public static function dataDelete(): array {
return [
[
'name',
@@ -72,22 +68,16 @@ public function deleteData() {
}
/**
- * @dataProvider deleteData
- *
- * @param string $configName
- * @param bool $configExists
- * @param bool $checkIfExists
- * @param int $expectedReturn
- * @param string $expectedMessage
+ * @dataProvider dataDelete
*/
- public function testDelete($configName, $configExists, $checkIfExists, $expectedReturn, $expectedMessage) {
- $this->config->expects(($checkIfExists) ? $this->once() : $this->never())
- ->method('getAppKeys')
+ public function testDelete(string $configName, bool $configExists, bool $checkIfExists, int $expectedReturn, string $expectedMessage): void {
+ $this->appConfig->expects(($checkIfExists) ? $this->once() : $this->never())
+ ->method('getKeys')
->with('app-name')
->willReturn($configExists ? [$configName] : []);
- $this->config->expects(($expectedReturn === 0) ? $this->once() : $this->never())
- ->method('deleteAppValue')
+ $this->appConfig->expects(($expectedReturn === 0) ? $this->once() : $this->never())
+ ->method('deleteKey')
->with('app-name', $configName);
$this->consoleInput->expects($this->exactly(2))
@@ -96,15 +86,13 @@ public function testDelete($configName, $configExists, $checkIfExists, $expected
['app', 'app-name'],
['name', $configName],
]);
- $this->consoleInput->expects($this->any())
- ->method('hasParameterOption')
+ $this->consoleInput->method('hasParameterOption')
->with('--error-if-not-exists')
->willReturn($checkIfExists);
- $this->consoleOutput->expects($this->any())
- ->method('writeln')
+ $this->consoleOutput->method('writeln')
->with($this->stringContains($expectedMessage));
- $this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]));
+ $this->assertSame($expectedReturn, self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]));
}
}
diff --git a/tests/Core/Command/Config/App/GetConfigTest.php b/tests/Core/Command/Config/App/GetConfigTest.php
index 79b79ea557631..89a75c0b5277f 100644
--- a/tests/Core/Command/Config/App/GetConfigTest.php
+++ b/tests/Core/Command/Config/App/GetConfigTest.php
@@ -1,4 +1,6 @@
config = $this->getMockBuilder(AppConfig::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
- $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
+ $this->appConfig = $this->createMock(IAppConfig::class);
+ $this->consoleInput = $this->createMock(InputInterface::class);
+ $this->consoleOutput = $this->createMock(OutputInterface::class);
- /** @var \OCP\IAppConfig $config */
- $this->command = new GetConfig($config);
+ $this->command = new GetConfig($this->appConfig);
}
- public function getData() {
+ public static function dataGet(): array {
return [
// String output as json
['name', 'newvalue', true, null, false, 'json', 0, json_encode('newvalue')],
@@ -83,21 +78,12 @@ public function getData() {
}
/**
- * @dataProvider getData
- *
- * @param string $configName
- * @param mixed $value
- * @param bool $configExists
- * @param mixed $defaultValue
- * @param bool $hasDefault
- * @param string $outputFormat
- * @param int $expectedReturn
- * @param string $expectedMessage
+ * @dataProvider dataGet
*/
- public function testGet($configName, $value, $configExists, $defaultValue, $hasDefault, $outputFormat, $expectedReturn, $expectedMessage) {
+ public function testGet(string $configName, mixed $value, bool $configExists, mixed $defaultValue, bool $hasDefault, string $outputFormat, int $expectedReturn, ?string $expectedMessage): void {
if (!$expectedReturn) {
if ($configExists) {
- $this->config->expects($this->once())
+ $this->appConfig->expects($this->once())
->method('getDetails')
->with('app-name', $configName)
->willReturn(['value' => $value]);
@@ -105,10 +91,10 @@ public function testGet($configName, $value, $configExists, $defaultValue, $hasD
}
if (!$configExists) {
- $this->config->expects($this->once())
- ->method('getDetails')
- ->with('app-name', $configName)
- ->willThrowException(new AppConfigUnknownKeyException());
+ $this->appConfig->expects($this->once())
+ ->method('getDetails')
+ ->with('app-name', $configName)
+ ->willThrowException(new AppConfigUnknownKeyException());
}
$this->consoleInput->expects($this->exactly(2))
@@ -117,14 +103,12 @@ public function testGet($configName, $value, $configExists, $defaultValue, $hasD
['app', 'app-name'],
['name', $configName],
]);
- $this->consoleInput->expects($this->any())
- ->method('getOption')
+ $this->consoleInput->method('getOption')
->willReturnMap([
['default-value', $defaultValue],
['output', $outputFormat],
]);
- $this->consoleInput->expects($this->any())
- ->method('hasParameterOption')
+ $this->consoleInput->method('hasParameterOption')
->willReturnMap([
['--output', false, true],
['--default-value', false, $hasDefault],
@@ -134,8 +118,7 @@ public function testGet($configName, $value, $configExists, $defaultValue, $hasD
global $output;
$output = '';
- $this->consoleOutput->expects($this->any())
- ->method('writeln')
+ $this->consoleOutput->method('writeln')
->willReturnCallback(function ($value) {
global $output;
$output .= $value . "\n";
@@ -143,7 +126,7 @@ public function testGet($configName, $value, $configExists, $defaultValue, $hasD
});
}
- $this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]));
+ $this->assertSame($expectedReturn, self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]));
if ($expectedMessage !== null) {
global $output;
diff --git a/tests/Core/Command/Config/App/SetConfigTest.php b/tests/Core/Command/Config/App/SetConfigTest.php
index 5c7e856f6fa98..099471228b476 100644
--- a/tests/Core/Command/Config/App/SetConfigTest.php
+++ b/tests/Core/Command/Config/App/SetConfigTest.php
@@ -1,4 +1,6 @@
config = $this->getMockBuilder(AppConfig::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
- $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
+ $this->appConfig = $this->createMock(AppConfig::class);
+ $this->consoleInput = $this->createMock(InputInterface::class);
+ $this->consoleOutput = $this->createMock(OutputInterface::class);
- /** @var \OCP\IAppConfig $config */
- $this->command = new SetConfig($config);
+ $this->command = new SetConfig($this->appConfig);
}
- public function setData() {
+ public static function dataSet(): array {
return [
[
'name',
@@ -63,33 +58,23 @@ public function setData() {
}
/**
- * @dataProvider setData
- *
- * @param string $configName
- * @param mixed $newValue
- * @param bool $configExists
- * @param bool $updateOnly
- * @param bool $updated
- * @param string $expectedMessage
+ * @dataProvider dataSet
*/
- public function testSet($configName, $newValue, $configExists, $updateOnly, $updated, $expectedMessage) {
- $this->config->expects($this->any())
- ->method('hasKey')
- ->with('app-name', $configName)
- ->willReturn($configExists);
+ public function testSet(string $configName, mixed $newValue, bool $configExists, bool $updateOnly, bool $updated, string $expectedMessage): void {
+ $this->appConfig->method('hasKey')
+ ->with('app-name', $configName)
+ ->willReturn($configExists);
if (!$configExists) {
- $this->config->expects($this->any())
- ->method('getValueType')
- ->willThrowException(new AppConfigUnknownKeyException());
+ $this->appConfig->method('getValueType')
+ ->willThrowException(new AppConfigUnknownKeyException());
} else {
- $this->config->expects($this->any())
- ->method('getValueType')
- ->willReturn(IAppConfig::VALUE_MIXED);
+ $this->appConfig->method('getValueType')
+ ->willReturn(IAppConfig::VALUE_MIXED);
}
if ($updated) {
- $this->config->expects($this->once())
+ $this->appConfig->expects($this->once())
->method('setValueMixed')
->with('app-name', $configName, $newValue);
}
@@ -100,25 +85,22 @@ public function testSet($configName, $newValue, $configExists, $updateOnly, $upd
['app', 'app-name'],
['name', $configName],
]);
- $this->consoleInput->expects($this->any())
- ->method('getOption')
+ $this->consoleInput->method('getOption')
->willReturnMap([
['value', $newValue],
['lazy', null],
['sensitive', null],
['no-interaction', true],
]);
- $this->consoleInput->expects($this->any())
- ->method('hasParameterOption')
+ $this->consoleInput->method('hasParameterOption')
->willReturnMap([
['--type', false, false],
['--value', false, true],
['--update-only', false, $updateOnly]
]);
- $this->consoleOutput->expects($this->any())
- ->method('writeln')
+ $this->consoleOutput->method('writeln')
->with($this->stringContains($expectedMessage));
- $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
+ self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
}