summaryrefslogtreecommitdiffstats
path: root/tests/Core
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2024-01-11 15:32:58 -0100
committerMaxence Lange <maxence@artificial-owl.com>2024-01-15 15:45:13 -0100
commitf7d0c74b1003af6c47dd6ec74f4ef904a2681d62 (patch)
treea0bfe1934fbec0ccf6651824589a0e67ae4f9d9f /tests/Core
parente5ef58b7b9b8f7a232666df17d286d43fb4d1201 (diff)
downloadnextcloud-server-f7d0c74b1003af6c47dd6ec74f4ef904a2681d62.tar.gz
nextcloud-server-f7d0c74b1003af6c47dd6ec74f4ef904a2681d62.zip
lazy AppConfig
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'tests/Core')
-rw-r--r--tests/Core/Command/Config/App/GetConfigTest.php23
-rw-r--r--tests/Core/Command/Config/App/SetConfigTest.php44
2 files changed, 44 insertions, 23 deletions
diff --git a/tests/Core/Command/Config/App/GetConfigTest.php b/tests/Core/Command/Config/App/GetConfigTest.php
index 521ecfbfb40..5988d8d867f 100644
--- a/tests/Core/Command/Config/App/GetConfigTest.php
+++ b/tests/Core/Command/Config/App/GetConfigTest.php
@@ -21,8 +21,9 @@
namespace Tests\Core\Command\Config\App;
+use OC\AppConfig;
use OC\Core\Command\Config\App\GetConfig;
-use OCP\IConfig;
+use OCP\Exceptions\AppConfigUnknownKeyException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;
@@ -42,13 +43,13 @@ class GetConfigTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $config = $this->config = $this->getMockBuilder(IConfig::class)
+ $config = $this->config = $this->getMockBuilder(AppConfig::class)
->disableOriginalConstructor()
->getMock();
$this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
- /** @var \OCP\IConfig $config */
+ /** @var \OCP\IAppConfig $config */
$this->command = new GetConfig($config);
}
@@ -108,20 +109,22 @@ class GetConfigTest extends TestCase {
* @param string $expectedMessage
*/
public function testGet($configName, $value, $configExists, $defaultValue, $hasDefault, $outputFormat, $expectedReturn, $expectedMessage) {
- $this->config->expects($this->atLeastOnce())
- ->method('getAppKeys')
- ->with('app-name')
- ->willReturn($configExists ? [$configName] : []);
-
if (!$expectedReturn) {
if ($configExists) {
$this->config->expects($this->once())
- ->method('getAppValue')
+ ->method('getDetails')
->with('app-name', $configName)
- ->willReturn($value);
+ ->willReturn(['value' => $value]);
}
}
+ if (!$configExists) {
+ $this->config->expects($this->once())
+ ->method('getDetails')
+ ->with('app-name', $configName)
+ ->willThrowException(new AppConfigUnknownKeyException());
+ }
+
$this->consoleInput->expects($this->exactly(2))
->method('getArgument')
->willReturnMap([
diff --git a/tests/Core/Command/Config/App/SetConfigTest.php b/tests/Core/Command/Config/App/SetConfigTest.php
index 88053f8c189..4918053048a 100644
--- a/tests/Core/Command/Config/App/SetConfigTest.php
+++ b/tests/Core/Command/Config/App/SetConfigTest.php
@@ -21,8 +21,10 @@
namespace Tests\Core\Command\Config\App;
+use OC\AppConfig;
use OC\Core\Command\Config\App\SetConfig;
-use OCP\IConfig;
+use OCP\Exceptions\AppConfigUnknownKeyException;
+use OCP\IAppConfig;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;
@@ -42,13 +44,13 @@ class SetConfigTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $config = $this->config = $this->getMockBuilder(IConfig::class)
+ $config = $this->config = $this->getMockBuilder(AppConfig::class)
->disableOriginalConstructor()
->getMock();
$this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
- /** @var \OCP\IConfig $config */
+ /** @var \OCP\IAppConfig $config */
$this->command = new SetConfig($config);
}
@@ -85,14 +87,24 @@ class SetConfigTest extends TestCase {
* @param string $expectedMessage
*/
public function testSet($configName, $newValue, $configExists, $updateOnly, $updated, $expectedMessage) {
- $this->config->expects($this->once())
- ->method('getAppKeys')
- ->with('app-name')
- ->willReturn($configExists ? [$configName] : []);
+ $this->config->expects($this->any())
+ ->method('hasKey')
+ ->with('app-name', $configName)
+ ->willReturn($configExists);
+
+ if (!$configExists) {
+ $this->config->expects($this->any())
+ ->method('getValueType')
+ ->willThrowException(new AppConfigUnknownKeyException());
+ } else {
+ $this->config->expects($this->any())
+ ->method('getValueType')
+ ->willReturn(IAppConfig::VALUE_MIXED);
+ }
if ($updated) {
$this->config->expects($this->once())
- ->method('setAppValue')
+ ->method('setValueMixed')
->with('app-name', $configName, $newValue);
}
@@ -104,13 +116,19 @@ class SetConfigTest extends TestCase {
]);
$this->consoleInput->expects($this->any())
->method('getOption')
- ->with('value')
- ->willReturn($newValue);
+ ->willReturnMap([
+ ['value', $newValue],
+ ['lazy', null],
+ ['sensitive', null],
+ ['no-interaction', true],
+ ]);
$this->consoleInput->expects($this->any())
->method('hasParameterOption')
- ->with('--update-only')
- ->willReturn($updateOnly);
-
+ ->willReturnMap([
+ ['--type', false, false],
+ ['--value', false, true],
+ ['--update-only', false, $updateOnly]
+ ]);
$this->consoleOutput->expects($this->any())
->method('writeln')
->with($this->stringContains($expectedMessage));