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.php83
-rw-r--r--tests/Core/Command/Config/App/GetConfigTest.php92
-rw-r--r--tests/Core/Command/Config/App/SetConfigTest.php97
-rw-r--r--tests/Core/Command/Config/ImportTest.php64
-rw-r--r--tests/Core/Command/Config/ListConfigsTest.php53
-rw-r--r--tests/Core/Command/Config/System/CastHelperTest.php66
-rw-r--r--tests/Core/Command/Config/System/DeleteConfigTest.php35
-rw-r--r--tests/Core/Command/Config/System/GetConfigTest.php29
-rw-r--r--tests/Core/Command/Config/System/SetConfigTest.php89
9 files changed, 238 insertions, 370 deletions
diff --git a/tests/Core/Command/Config/App/DeleteConfigTest.php b/tests/Core/Command/Config/App/DeleteConfigTest.php
index 2c9482b57f6..9e43f389214 100644
--- a/tests/Core/Command/Config/App/DeleteConfigTest.php
+++ b/tests/Core/Command/Config/App/DeleteConfigTest.php
@@ -1,58 +1,43 @@
<?php
+
+declare(strict_types=1);
/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Tests\Core\Command\Config\App;
+use OC\Config\ConfigManager;
use OC\Core\Command\Config\App\DeleteConfig;
-use OCP\IConfig;
+use OCP\IAppConfig;
+use PHPUnit\Framework\MockObject\MockObject;
+use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;
class DeleteConfigTest extends TestCase {
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
- protected $config;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject */
- protected $consoleInput;
- /** @var \PHPUnit\Framework\MockObject\MockObject */
- protected $consoleOutput;
-
- /** @var \Symfony\Component\Console\Command\Command */
- protected $command;
+ protected IAppConfig&MockObject $appConfig;
+ protected ConfigManager&MockObject $configManager;
+ protected InputInterface&MockObject $consoleInput;
+ protected OutputInterface&MockObject $consoleOutput;
+ protected Command $command;
protected function setUp(): void {
parent::setUp();
- $this->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->configManager = $this->createMock(ConfigManager::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, $this->configManager);
}
- public function deleteData() {
+ public static function dataDelete(): array {
return [
[
'name',
@@ -85,23 +70,15 @@ class DeleteConfigTest extends TestCase {
];
}
- /**
- * @dataProvider deleteData
- *
- * @param string $configName
- * @param bool $configExists
- * @param bool $checkIfExists
- * @param int $expectedReturn
- * @param string $expectedMessage
- */
- public function testDelete($configName, $configExists, $checkIfExists, $expectedReturn, $expectedMessage) {
- $this->config->expects(($checkIfExists) ? $this->once() : $this->never())
- ->method('getAppKeys')
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataDelete')]
+ 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))
@@ -110,15 +87,13 @@ class DeleteConfigTest extends TestCase {
['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 5988d8d867f..13392cddf55 100644
--- a/tests/Core/Command/Config/App/GetConfigTest.php
+++ b/tests/Core/Command/Config/App/GetConfigTest.php
@@ -1,60 +1,44 @@
<?php
+
+declare(strict_types=1);
/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Tests\Core\Command\Config\App;
-use OC\AppConfig;
+use OC\Config\ConfigManager;
use OC\Core\Command\Config\App\GetConfig;
use OCP\Exceptions\AppConfigUnknownKeyException;
+use OCP\IAppConfig;
+use PHPUnit\Framework\MockObject\MockObject;
+use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;
class GetConfigTest extends TestCase {
- /** @var \PHPUnit\Framework\MockObject\MockObject */
- protected $config;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject */
- protected $consoleInput;
- /** @var \PHPUnit\Framework\MockObject\MockObject */
- protected $consoleOutput;
-
- /** @var \Symfony\Component\Console\Command\Command */
- protected $command;
+ protected IAppConfig&MockObject $appConfig;
+ protected ConfigManager&MockObject $configManager;
+ protected InputInterface&MockObject $consoleInput;
+ protected OutputInterface&MockObject $consoleOutput;
+ protected Command $command;
protected function setUp(): void {
parent::setUp();
- $config = $this->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->configManager = $this->createMock(ConfigManager::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, $this->configManager);
}
- public function getData() {
+ public static function dataGet(): array {
return [
// String output as json
['name', 'newvalue', true, null, false, 'json', 0, json_encode('newvalue')],
@@ -96,22 +80,11 @@ class GetConfigTest extends TestCase {
];
}
- /**
- * @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
- */
- public function testGet($configName, $value, $configExists, $defaultValue, $hasDefault, $outputFormat, $expectedReturn, $expectedMessage) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGet')]
+ 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]);
@@ -119,10 +92,10 @@ class GetConfigTest extends TestCase {
}
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))
@@ -131,14 +104,12 @@ class GetConfigTest extends TestCase {
['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],
@@ -148,8 +119,7 @@ class GetConfigTest extends TestCase {
global $output;
$output = '';
- $this->consoleOutput->expects($this->any())
- ->method('writeln')
+ $this->consoleOutput->method('writeln')
->willReturnCallback(function ($value) {
global $output;
$output .= $value . "\n";
@@ -157,7 +127,7 @@ class GetConfigTest extends TestCase {
});
}
- $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 4918053048a..a5c62368163 100644
--- a/tests/Core/Command/Config/App/SetConfigTest.php
+++ b/tests/Core/Command/Config/App/SetConfigTest.php
@@ -1,61 +1,45 @@
<?php
+
+declare(strict_types=1);
/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
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;
+use PHPUnit\Framework\MockObject\MockObject;
+use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;
class SetConfigTest extends TestCase {
- /** @var \PHPUnit\Framework\MockObject\MockObject */
- protected $config;
-
- /** @var \PHPUnit\Framework\MockObject\MockObject */
- protected $consoleInput;
- /** @var \PHPUnit\Framework\MockObject\MockObject */
- protected $consoleOutput;
-
- /** @var \Symfony\Component\Console\Command\Command */
- protected $command;
+ protected IAppConfig&MockObject $appConfig;
+ protected ConfigManager&MockObject $configManager;
+ protected InputInterface&MockObject $consoleInput;
+ protected OutputInterface&MockObject $consoleOutput;
+ protected Command $command;
protected function setUp(): void {
parent::setUp();
- $config = $this->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->configManager = $this->createMock(ConfigManager::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, $this->configManager);
}
- public function setData() {
+ public static function dataSet(): array {
return [
[
'name',
@@ -76,34 +60,22 @@ class SetConfigTest extends TestCase {
];
}
- /**
- * @dataProvider setData
- *
- * @param string $configName
- * @param mixed $newValue
- * @param bool $configExists
- * @param bool $updateOnly
- * @param bool $updated
- * @param string $expectedMessage
- */
- public function testSet($configName, $newValue, $configExists, $updateOnly, $updated, $expectedMessage) {
- $this->config->expects($this->any())
- ->method('hasKey')
- ->with('app-name', $configName)
- ->willReturn($configExists);
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSet')]
+ 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);
}
@@ -114,25 +86,22 @@ class SetConfigTest extends TestCase {
['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]);
}
}
diff --git a/tests/Core/Command/Config/ImportTest.php b/tests/Core/Command/Config/ImportTest.php
index c9cc256bea9..14cdd714d12 100644
--- a/tests/Core/Command/Config/ImportTest.php
+++ b/tests/Core/Command/Config/ImportTest.php
@@ -1,22 +1,9 @@
<?php
+
/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Tests\Core\Command\Config;
@@ -48,11 +35,11 @@ class ImportTest extends TestCase {
$this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
- /** @var \OCP\IConfig $config */
+ /** @var IConfig $config */
$this->command = new Import($config);
}
- public function validateAppsArrayData() {
+ public static function validateAppsArrayData(): array {
return [
[0],
[1],
@@ -63,16 +50,15 @@ class ImportTest extends TestCase {
}
/**
- * @dataProvider validateAppsArrayData
- *
* @param mixed $configValue
*/
- public function testValidateAppsArray($configValue) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('validateAppsArrayData')]
+ public function testValidateAppsArray($configValue): void {
$this->invokePrivate($this->command, 'validateAppsArray', [['app' => ['name' => $configValue]]]);
$this->assertTrue(true, 'Asserting that no exception is thrown');
}
- public function validateAppsArrayThrowsData() {
+ public static function validateAppsArrayThrowsData(): array {
return [
[false],
[true],
@@ -82,11 +68,10 @@ class ImportTest extends TestCase {
}
/**
- * @dataProvider validateAppsArrayThrowsData
- *
* @param mixed $configValue
*/
- public function testValidateAppsArrayThrows($configValue) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('validateAppsArrayThrowsData')]
+ public function testValidateAppsArrayThrows($configValue): void {
try {
$this->invokePrivate($this->command, 'validateAppsArray', [['app' => ['name' => $configValue]]]);
$this->fail('Did not throw expected UnexpectedValueException');
@@ -95,7 +80,7 @@ class ImportTest extends TestCase {
}
}
- public function checkTypeRecursivelyData() {
+ public static function checkTypeRecursivelyData(): array {
return [
[0],
[1],
@@ -112,16 +97,15 @@ class ImportTest extends TestCase {
}
/**
- * @dataProvider checkTypeRecursivelyData
- *
* @param mixed $configValue
*/
- public function testCheckTypeRecursively($configValue) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('checkTypeRecursivelyData')]
+ public function testCheckTypeRecursively($configValue): void {
$this->invokePrivate($this->command, 'checkTypeRecursively', [$configValue, 'name']);
$this->assertTrue(true, 'Asserting that no exception is thrown');
}
- public function checkTypeRecursivelyThrowsData() {
+ public static function checkTypeRecursivelyThrowsData(): array {
return [
[new \Exception()],
[[new \Exception()]],
@@ -131,11 +115,10 @@ class ImportTest extends TestCase {
}
/**
- * @dataProvider checkTypeRecursivelyThrowsData
- *
* @param mixed $configValue
*/
- public function testCheckTypeRecursivelyThrows($configValue) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('checkTypeRecursivelyThrowsData')]
+ public function testCheckTypeRecursivelyThrows($configValue): void {
try {
$this->invokePrivate($this->command, 'checkTypeRecursively', [$configValue, 'name']);
$this->fail('Did not throw expected UnexpectedValueException');
@@ -144,7 +127,7 @@ class ImportTest extends TestCase {
}
}
- public function validateArrayData() {
+ public static function validateArrayData(): array {
return [
[['system' => []]],
[['apps' => []]],
@@ -153,16 +136,15 @@ class ImportTest extends TestCase {
}
/**
- * @dataProvider validateArrayData
- *
* @param array $configArray
*/
- public function testValidateArray($configArray) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('validateArrayData')]
+ public function testValidateArray($configArray): void {
$this->invokePrivate($this->command, 'validateArray', [$configArray]);
$this->assertTrue(true, 'Asserting that no exception is thrown');
}
- public function validateArrayThrowsData() {
+ public static function validateArrayThrowsData(): array {
return [
[[], 'At least one key of the following is expected:'],
[[0 => []], 'Found invalid entries in root'],
@@ -171,12 +153,12 @@ class ImportTest extends TestCase {
}
/**
- * @dataProvider validateArrayThrowsData
*
* @param mixed $configArray
* @param string $expectedException
*/
- public function testValidateArrayThrows($configArray, $expectedException) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('validateArrayThrowsData')]
+ public function testValidateArrayThrows($configArray, $expectedException): void {
try {
$this->invokePrivate($this->command, 'validateArray', [$configArray]);
$this->fail('Did not throw expected UnexpectedValueException');
diff --git a/tests/Core/Command/Config/ListConfigsTest.php b/tests/Core/Command/Config/ListConfigsTest.php
index 01d5f512494..e4af55116c0 100644
--- a/tests/Core/Command/Config/ListConfigsTest.php
+++ b/tests/Core/Command/Config/ListConfigsTest.php
@@ -1,26 +1,14 @@
<?php
+
/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Tests\Core\Command\Config;
+use OC\Config\ConfigManager;
use OC\Core\Command\Config\ListConfigs;
use OC\SystemConfig;
use OCP\IAppConfig;
@@ -34,6 +22,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;
@@ -52,15 +42,20 @@ 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 function listData() {
+ public static function listData(): array {
return [
[
'all',
@@ -75,10 +70,10 @@ class ListConfigsTest extends TestCase {
],
// app config
[
- ['files', false, [
+ ['files', [
'enabled' => 'yes',
]],
- ['core', false, [
+ ['core', [
'global_cache_gc_lastrun' => '1430388388',
]],
],
@@ -155,10 +150,10 @@ class ListConfigsTest extends TestCase {
],
// app config
[
- ['files', false, [
+ ['files', [
'enabled' => 'yes',
]],
- ['core', false, [
+ ['core', [
'global_cache_gc_lastrun' => '1430388388',
]],
],
@@ -190,10 +185,10 @@ class ListConfigsTest extends TestCase {
],
// app config
[
- ['files', false, [
+ ['files', [
'enabled' => 'yes',
]],
- ['core', false, [
+ ['core', [
'global_cache_gc_lastrun' => '1430388388',
]],
],
@@ -218,10 +213,10 @@ class ListConfigsTest extends TestCase {
],
// app config
[
- ['files', false, [
+ ['files', [
'enabled' => 'yes',
]],
- ['core', false, [
+ ['core', [
'global_cache_gc_lastrun' => '1430388388',
]],
],
@@ -267,7 +262,6 @@ class ListConfigsTest extends TestCase {
}
/**
- * @dataProvider listData
*
* @param string $app
* @param array $systemConfigs
@@ -276,7 +270,8 @@ class ListConfigsTest extends TestCase {
* @param bool $private
* @param string $expected
*/
- public function testList($app, $systemConfigs, $systemConfigMap, $appConfig, $private, $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('listData')]
+ public function testList($app, $systemConfigs, $systemConfigMap, $appConfig, $private, $expected): void {
$this->systemConfig->expects($this->any())
->method('getKeys')
->willReturn($systemConfigs);
diff --git a/tests/Core/Command/Config/System/CastHelperTest.php b/tests/Core/Command/Config/System/CastHelperTest.php
new file mode 100644
index 00000000000..924887daaf7
--- /dev/null
+++ b/tests/Core/Command/Config/System/CastHelperTest.php
@@ -0,0 +1,66 @@
+<?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']],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\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'],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\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/DeleteConfigTest.php b/tests/Core/Command/Config/System/DeleteConfigTest.php
index b72f06b35bf..b0a3580e1cd 100644
--- a/tests/Core/Command/Config/System/DeleteConfigTest.php
+++ b/tests/Core/Command/Config/System/DeleteConfigTest.php
@@ -1,22 +1,9 @@
<?php
+
/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Tests\Core\Command\Config\System;
@@ -48,11 +35,11 @@ class DeleteConfigTest extends TestCase {
$this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
- /** @var \OC\SystemConfig $systemConfig */
+ /** @var SystemConfig $systemConfig */
$this->command = new DeleteConfig($systemConfig);
}
- public function deleteData() {
+ public static function deleteData(): array {
return [
[
'name1',
@@ -86,7 +73,6 @@ class DeleteConfigTest extends TestCase {
}
/**
- * @dataProvider deleteData
*
* @param string $configName
* @param bool $configExists
@@ -94,7 +80,8 @@ class DeleteConfigTest extends TestCase {
* @param int $expectedReturn
* @param string $expectedMessage
*/
- public function testDelete($configName, $configExists, $checkIfExists, $expectedReturn, $expectedMessage) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('deleteData')]
+ public function testDelete($configName, $configExists, $checkIfExists, $expectedReturn, $expectedMessage): void {
$this->systemConfig->expects(($checkIfExists) ? $this->once() : $this->never())
->method('getKeys')
->willReturn($configExists ? [$configName] : []);
@@ -119,7 +106,7 @@ class DeleteConfigTest extends TestCase {
$this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]));
}
- public function deleteArrayData() {
+ public static function deleteArrayData(): array {
return [
[
['name', 'sub'],
@@ -179,7 +166,6 @@ class DeleteConfigTest extends TestCase {
}
/**
- * @dataProvider deleteArrayData
*
* @param string[] $configNames
* @param bool $configKeyExists
@@ -189,7 +175,8 @@ class DeleteConfigTest extends TestCase {
* @param int $expectedReturn
* @param string $expectedMessage
*/
- public function testArrayDelete(array $configNames, $configKeyExists, $checkIfKeyExists, $configValue, $updateValue, $expectedReturn, $expectedMessage) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('deleteArrayData')]
+ public function testArrayDelete(array $configNames, $configKeyExists, $checkIfKeyExists, $configValue, $updateValue, $expectedReturn, $expectedMessage): void {
$this->systemConfig->expects(($checkIfKeyExists) ? $this->once() : $this->never())
->method('getKeys')
->willReturn($configKeyExists ? [$configNames[0]] : []);
diff --git a/tests/Core/Command/Config/System/GetConfigTest.php b/tests/Core/Command/Config/System/GetConfigTest.php
index 3a6bb1acb50..8b84fd14198 100644
--- a/tests/Core/Command/Config/System/GetConfigTest.php
+++ b/tests/Core/Command/Config/System/GetConfigTest.php
@@ -1,22 +1,9 @@
<?php
+
/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Tests\Core\Command\Config\System;
@@ -48,12 +35,12 @@ class GetConfigTest extends TestCase {
$this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
- /** @var \OC\SystemConfig $systemConfig */
+ /** @var SystemConfig $systemConfig */
$this->command = new GetConfig($systemConfig);
}
- public function getData() {
+ public static function getData(): array {
return [
// String output as json
['name', 'newvalue', true, null, false, 'json', 0, json_encode('newvalue')],
@@ -102,7 +89,6 @@ class GetConfigTest extends TestCase {
}
/**
- * @dataProvider getData
*
* @param string[] $configNames
* @param mixed $value
@@ -113,7 +99,8 @@ class GetConfigTest extends TestCase {
* @param int $expectedReturn
* @param string $expectedMessage
*/
- public function testGet($configNames, $value, $configExists, $defaultValue, $hasDefault, $outputFormat, $expectedReturn, $expectedMessage) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('getData')]
+ public function testGet($configNames, $value, $configExists, $defaultValue, $hasDefault, $outputFormat, $expectedReturn, $expectedMessage): void {
if (is_array($configNames)) {
$configName = $configNames[0];
} else {
diff --git a/tests/Core/Command/Config/System/SetConfigTest.php b/tests/Core/Command/Config/System/SetConfigTest.php
index a53607e8a39..a99b832c160 100644
--- a/tests/Core/Command/Config/System/SetConfigTest.php
+++ b/tests/Core/Command/Config/System/SetConfigTest.php
@@ -1,26 +1,14 @@
<?php
+
/**
- * @author Joas Schilling <nickvergessen@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
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;
@@ -48,12 +36,12 @@ class SetConfigTest extends TestCase {
$this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
- /** @var \OC\SystemConfig $systemConfig */
- $this->command = new SetConfig($systemConfig);
+ /** @var SystemConfig $systemConfig */
+ $this->command = new SetConfig($systemConfig, new CastHelper());
}
- public function setData() {
+ public static function dataTest() {
return [
[['name'], 'newvalue', null, 'newvalue'],
[['a', 'b', 'c'], 'foobar', null, ['b' => ['c' => 'foobar']]],
@@ -62,14 +50,14 @@ class SetConfigTest extends TestCase {
}
/**
- * @dataProvider setData
*
* @param array $configNames
* @param string $newValue
* @param mixed $existingData
* @param mixed $expectedValue
*/
- public function testSet($configNames, $newValue, $existingData, $expectedValue) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTest')]
+ public function testSet($configNames, $newValue, $existingData, $expectedValue): void {
$this->systemConfig->expects($this->once())
->method('setValue')
->with($configNames[0], $expectedValue);
@@ -90,7 +78,7 @@ class SetConfigTest extends TestCase {
$this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
- public function setUpdateOnlyProvider() {
+ public static function setUpdateOnlyProvider(): array {
return [
[['name'], null],
[['a', 'b', 'c'], null],
@@ -99,10 +87,8 @@ class SetConfigTest extends TestCase {
];
}
- /**
- * @dataProvider setUpdateOnlyProvider
- */
- public function testSetUpdateOnly($configNames, $existingData) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('setUpdateOnlyProvider')]
+ public function testSetUpdateOnly($configNames, $existingData): void {
$this->expectException(\UnexpectedValueException::class);
$this->systemConfig->expects($this->never())
@@ -126,53 +112,4 @@ class SetConfigTest extends TestCase {
$this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
-
- public function castValueProvider() {
- 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) {
- $this->assertSame($expectedValue,
- $this->invokePrivate($this->command, 'castValue', [$value, $type])
- );
- }
-
- public function castValueInvalidProvider() {
- return [
- ['123', 'foobar'],
-
- [null, 'integer'],
- ['abc', 'integer'],
- ['76ggg', 'double'],
- ['true', 'float'],
- ['foobar', 'boolean'],
- ];
- }
-
- /**
- * @dataProvider castValueInvalidProvider
- */
- public function testCastValueInvalid($value, $type) {
- $this->expectException(\InvalidArgumentException::class);
-
- $this->invokePrivate($this->command, 'castValue', [$value, $type]);
- }
}