aboutsummaryrefslogtreecommitdiffstats
path: root/tests/Core/Command/Config
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Core/Command/Config')
-rw-r--r--tests/Core/Command/Config/App/DeleteConfigTest.php5
-rw-r--r--tests/Core/Command/Config/App/GetConfigTest.php5
-rw-r--r--tests/Core/Command/Config/App/SetConfigTest.php5
-rw-r--r--tests/Core/Command/Config/ListConfigsTest.php10
-rw-r--r--tests/Core/Command/Config/System/CastHelperTest.php69
-rw-r--r--tests/Core/Command/Config/System/SetConfigTest.php52
6 files changed, 92 insertions, 54 deletions
diff --git a/tests/Core/Command/Config/App/DeleteConfigTest.php b/tests/Core/Command/Config/App/DeleteConfigTest.php
index 1e44c2aafe6..6f7bfbf3a7c 100644
--- a/tests/Core/Command/Config/App/DeleteConfigTest.php
+++ b/tests/Core/Command/Config/App/DeleteConfigTest.php
@@ -9,6 +9,7 @@ declare(strict_types=1);
namespace Tests\Core\Command\Config\App;
+use OC\Config\ConfigManager;
use OC\Core\Command\Config\App\DeleteConfig;
use OCP\IAppConfig;
use PHPUnit\Framework\MockObject\MockObject;
@@ -19,6 +20,7 @@ use Test\TestCase;
class DeleteConfigTest extends TestCase {
protected IAppConfig&MockObject $appConfig;
+ protected ConfigManager&MockObject $configManager;
protected InputInterface&MockObject $consoleInput;
protected OutputInterface&MockObject $consoleOutput;
protected Command $command;
@@ -27,10 +29,11 @@ class DeleteConfigTest extends TestCase {
parent::setUp();
$this->appConfig = $this->createMock(IAppConfig::class);
+ $this->configManager = $this->createMock(ConfigManager::class);
$this->consoleInput = $this->createMock(InputInterface::class);
$this->consoleOutput = $this->createMock(OutputInterface::class);
- $this->command = new DeleteConfig($this->appConfig);
+ $this->command = new DeleteConfig($this->appConfig, $this->configManager);
}
diff --git a/tests/Core/Command/Config/App/GetConfigTest.php b/tests/Core/Command/Config/App/GetConfigTest.php
index 89a75c0b527..63a02f263d0 100644
--- a/tests/Core/Command/Config/App/GetConfigTest.php
+++ b/tests/Core/Command/Config/App/GetConfigTest.php
@@ -9,6 +9,7 @@ declare(strict_types=1);
namespace Tests\Core\Command\Config\App;
+use OC\Config\ConfigManager;
use OC\Core\Command\Config\App\GetConfig;
use OCP\Exceptions\AppConfigUnknownKeyException;
use OCP\IAppConfig;
@@ -20,6 +21,7 @@ use Test\TestCase;
class GetConfigTest extends TestCase {
protected IAppConfig&MockObject $appConfig;
+ protected ConfigManager&MockObject $configManager;
protected InputInterface&MockObject $consoleInput;
protected OutputInterface&MockObject $consoleOutput;
protected Command $command;
@@ -28,10 +30,11 @@ class GetConfigTest extends TestCase {
parent::setUp();
$this->appConfig = $this->createMock(IAppConfig::class);
+ $this->configManager = $this->createMock(ConfigManager::class);
$this->consoleInput = $this->createMock(InputInterface::class);
$this->consoleOutput = $this->createMock(OutputInterface::class);
- $this->command = new GetConfig($this->appConfig);
+ $this->command = new GetConfig($this->appConfig, $this->configManager);
}
diff --git a/tests/Core/Command/Config/App/SetConfigTest.php b/tests/Core/Command/Config/App/SetConfigTest.php
index 099471228b4..596439d85a8 100644
--- a/tests/Core/Command/Config/App/SetConfigTest.php
+++ b/tests/Core/Command/Config/App/SetConfigTest.php
@@ -10,6 +10,7 @@ declare(strict_types=1);
namespace Tests\Core\Command\Config\App;
use OC\AppConfig;
+use OC\Config\ConfigManager;
use OC\Core\Command\Config\App\SetConfig;
use OCP\Exceptions\AppConfigUnknownKeyException;
use OCP\IAppConfig;
@@ -21,6 +22,7 @@ use Test\TestCase;
class SetConfigTest extends TestCase {
protected IAppConfig&MockObject $appConfig;
+ protected ConfigManager&MockObject $configManager;
protected InputInterface&MockObject $consoleInput;
protected OutputInterface&MockObject $consoleOutput;
protected Command $command;
@@ -29,10 +31,11 @@ class SetConfigTest extends TestCase {
parent::setUp();
$this->appConfig = $this->createMock(AppConfig::class);
+ $this->configManager = $this->createMock(ConfigManager::class);
$this->consoleInput = $this->createMock(InputInterface::class);
$this->consoleOutput = $this->createMock(OutputInterface::class);
- $this->command = new SetConfig($this->appConfig);
+ $this->command = new SetConfig($this->appConfig, $this->configManager);
}
diff --git a/tests/Core/Command/Config/ListConfigsTest.php b/tests/Core/Command/Config/ListConfigsTest.php
index 12a6e6f1cf8..216a6133579 100644
--- a/tests/Core/Command/Config/ListConfigsTest.php
+++ b/tests/Core/Command/Config/ListConfigsTest.php
@@ -7,6 +7,7 @@
namespace Tests\Core\Command\Config;
+use OC\Config\ConfigManager;
use OC\Core\Command\Config\ListConfigs;
use OC\SystemConfig;
use OCP\IAppConfig;
@@ -20,6 +21,8 @@ class ListConfigsTest extends TestCase {
protected $appConfig;
/** @var \PHPUnit\Framework\MockObject\MockObject */
protected $systemConfig;
+ /** @var \PHPUnit\Framework\MockObject\MockObject */
+ protected $configManager;
/** @var \PHPUnit\Framework\MockObject\MockObject */
protected $consoleInput;
@@ -38,12 +41,17 @@ class ListConfigsTest extends TestCase {
$appConfig = $this->appConfig = $this->getMockBuilder(IAppConfig::class)
->disableOriginalConstructor()
->getMock();
+ $configManager = $this->configManager = $this->getMockBuilder(ConfigManager::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+
$this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
/** @var \OC\SystemConfig $systemConfig */
/** @var \OCP\IAppConfig $appConfig */
- $this->command = new ListConfigs($systemConfig, $appConfig);
+ /** @var ConfigManager $configManager */
+ $this->command = new ListConfigs($systemConfig, $appConfig, $configManager);
}
public static function listData(): array {
diff --git a/tests/Core/Command/Config/System/CastHelperTest.php b/tests/Core/Command/Config/System/CastHelperTest.php
new file mode 100644
index 00000000000..0d3ca032026
--- /dev/null
+++ b/tests/Core/Command/Config/System/CastHelperTest.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+namespace Core\Command\Config\System;
+
+use OC\Core\Command\Config\System\CastHelper;
+use Test\TestCase;
+
+class CastHelperTest extends TestCase {
+ private CastHelper $castHelper;
+
+ protected function setUp(): void {
+ parent::setUp();
+ $this->castHelper = new CastHelper();
+ }
+
+ public static function castValueProvider(): array {
+ return [
+ [null, 'string', ['value' => '', 'readable-value' => 'empty string']],
+
+ ['abc', 'string', ['value' => 'abc', 'readable-value' => 'string abc']],
+
+ ['123', 'integer', ['value' => 123, 'readable-value' => 'integer 123']],
+ ['456', 'int', ['value' => 456, 'readable-value' => 'integer 456']],
+
+ ['2.25', 'double', ['value' => 2.25, 'readable-value' => 'double 2.25']],
+ ['0.5', 'float', ['value' => 0.5, 'readable-value' => 'double 0.5']],
+
+ ['', 'null', ['value' => null, 'readable-value' => 'null']],
+
+ ['true', 'boolean', ['value' => true, 'readable-value' => 'boolean true']],
+ ['false', 'bool', ['value' => false, 'readable-value' => 'boolean false']],
+ ];
+ }
+
+ /**
+ * @dataProvider castValueProvider
+ */
+ public function testCastValue($value, $type, $expectedValue): void {
+ $this->assertSame(
+ $expectedValue,
+ $this->castHelper->castValue($value, $type)
+ );
+ }
+
+ public static function castValueInvalidProvider(): array {
+ return [
+ ['123', 'foobar'],
+
+ [null, 'integer'],
+ ['abc', 'integer'],
+ ['76ggg', 'double'],
+ ['true', 'float'],
+ ['foobar', 'boolean'],
+ ];
+ }
+
+ /**
+ * @dataProvider castValueInvalidProvider
+ */
+ public function testCastValueInvalid($value, $type): void {
+ $this->expectException(\InvalidArgumentException::class);
+
+ $this->castHelper->castValue($value, $type);
+ }
+}
diff --git a/tests/Core/Command/Config/System/SetConfigTest.php b/tests/Core/Command/Config/System/SetConfigTest.php
index cfe93a15eaf..73fee8bee5f 100644
--- a/tests/Core/Command/Config/System/SetConfigTest.php
+++ b/tests/Core/Command/Config/System/SetConfigTest.php
@@ -7,6 +7,7 @@
namespace Tests\Core\Command\Config\System;
+use OC\Core\Command\Config\System\CastHelper;
use OC\Core\Command\Config\System\SetConfig;
use OC\SystemConfig;
use Symfony\Component\Console\Input\InputInterface;
@@ -35,7 +36,7 @@ class SetConfigTest extends TestCase {
$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
/** @var \OC\SystemConfig $systemConfig */
- $this->command = new SetConfig($systemConfig);
+ $this->command = new SetConfig($systemConfig, new CastHelper());
}
@@ -112,53 +113,4 @@ class SetConfigTest extends TestCase {
$this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
-
- public static function castValueProvider(): array {
- return [
- [null, 'string', ['value' => '', 'readable-value' => 'empty string']],
-
- ['abc', 'string', ['value' => 'abc', 'readable-value' => 'string abc']],
-
- ['123', 'integer', ['value' => 123, 'readable-value' => 'integer 123']],
- ['456', 'int', ['value' => 456, 'readable-value' => 'integer 456']],
-
- ['2.25', 'double', ['value' => 2.25, 'readable-value' => 'double 2.25']],
- ['0.5', 'float', ['value' => 0.5, 'readable-value' => 'double 0.5']],
-
- ['', 'null', ['value' => null, 'readable-value' => 'null']],
-
- ['true', 'boolean', ['value' => true, 'readable-value' => 'boolean true']],
- ['false', 'bool', ['value' => false, 'readable-value' => 'boolean false']],
- ];
- }
-
- /**
- * @dataProvider castValueProvider
- */
- public function testCastValue($value, $type, $expectedValue): void {
- $this->assertSame($expectedValue,
- $this->invokePrivate($this->command, 'castValue', [$value, $type])
- );
- }
-
- public static function castValueInvalidProvider(): array {
- return [
- ['123', 'foobar'],
-
- [null, 'integer'],
- ['abc', 'integer'],
- ['76ggg', 'double'],
- ['true', 'float'],
- ['foobar', 'boolean'],
- ];
- }
-
- /**
- * @dataProvider castValueInvalidProvider
- */
- public function testCastValueInvalid($value, $type): void {
- $this->expectException(\InvalidArgumentException::class);
-
- $this->invokePrivate($this->command, 'castValue', [$value, $type]);
- }
}