aboutsummaryrefslogtreecommitdiffstats
path: root/tests/Core/Command/Config/System
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Core/Command/Config/System')
-rw-r--r--tests/Core/Command/Config/System/CastHelperTest.php66
-rw-r--r--tests/Core/Command/Config/System/DeleteConfigTest.php11
-rw-r--r--tests/Core/Command/Config/System/GetConfigTest.php7
-rw-r--r--tests/Core/Command/Config/System/SetConfigTest.php65
4 files changed, 84 insertions, 65 deletions
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 872079ef4c2..b0a3580e1cd 100644
--- a/tests/Core/Command/Config/System/DeleteConfigTest.php
+++ b/tests/Core/Command/Config/System/DeleteConfigTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -34,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',
@@ -72,7 +73,6 @@ class DeleteConfigTest extends TestCase {
}
/**
- * @dataProvider deleteData
*
* @param string $configName
* @param bool $configExists
@@ -80,6 +80,7 @@ class DeleteConfigTest extends TestCase {
* @param int $expectedReturn
* @param string $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')
@@ -105,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'],
@@ -165,7 +166,6 @@ class DeleteConfigTest extends TestCase {
}
/**
- * @dataProvider deleteArrayData
*
* @param string[] $configNames
* @param bool $configKeyExists
@@ -175,6 +175,7 @@ class DeleteConfigTest extends TestCase {
* @param int $expectedReturn
* @param string $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')
diff --git a/tests/Core/Command/Config/System/GetConfigTest.php b/tests/Core/Command/Config/System/GetConfigTest.php
index f05d0e384ee..8b84fd14198 100644
--- a/tests/Core/Command/Config/System/GetConfigTest.php
+++ b/tests/Core/Command/Config/System/GetConfigTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -34,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')],
@@ -88,7 +89,6 @@ class GetConfigTest extends TestCase {
}
/**
- * @dataProvider getData
*
* @param string[] $configNames
* @param mixed $value
@@ -99,6 +99,7 @@ class GetConfigTest extends TestCase {
* @param int $expectedReturn
* @param string $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];
diff --git a/tests/Core/Command/Config/System/SetConfigTest.php b/tests/Core/Command/Config/System/SetConfigTest.php
index 2905af5c3d7..a99b832c160 100644
--- a/tests/Core/Command/Config/System/SetConfigTest.php
+++ b/tests/Core/Command/Config/System/SetConfigTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -7,6 +8,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;
@@ -34,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']]],
@@ -48,13 +50,13 @@ class SetConfigTest extends TestCase {
}
/**
- * @dataProvider setData
*
* @param array $configNames
* @param string $newValue
* @param mixed $existingData
* @param mixed $expectedValue
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTest')]
public function testSet($configNames, $newValue, $existingData, $expectedValue): void {
$this->systemConfig->expects($this->once())
->method('setValue')
@@ -76,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],
@@ -85,9 +87,7 @@ class SetConfigTest extends TestCase {
];
}
- /**
- * @dataProvider setUpdateOnlyProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('setUpdateOnlyProvider')]
public function testSetUpdateOnly($configNames, $existingData): void {
$this->expectException(\UnexpectedValueException::class);
@@ -112,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): void {
- $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): void {
- $this->expectException(\InvalidArgumentException::class);
-
- $this->invokePrivate($this->command, 'castValue', [$value, $type]);
- }
}