Skip to content

Commit cc109f3

Browse files
committed
test(iappconfig): Add more tests with IAppConfig already imported
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent 6546aff commit cc109f3

3 files changed

Lines changed: 124 additions & 5 deletions

File tree

src/Rector/ReplaceIConfigWithIAppConfigRector.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,9 @@ function (Node $subNode) use ($propertyNames, $deprecatedMethods, &$calls): ?Nod
188188
if (!$this->isName($propertyFetch->var, 'this')) {
189189
return null;
190190
}
191-
foreach ($propertyNames as $propertyName) {
192-
if ($this->isName($propertyFetch->name, $propertyName)) {
193-
$calls[] = $subNode;
194191

195-
break;
196-
}
192+
if ($this->isNames($propertyFetch->name, $propertyNames)) {
193+
$calls[] = $subNode;
197194
}
198195

199196
return null;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/*
4+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
namespace Nextcloud\Rector\Test\Rector\ReplaceIConfigWithIAppConfigRector\Fixture;
9+
10+
use OCP\IAppConfig;
11+
use OCP\IConfig;
12+
13+
class SomeClass
14+
{
15+
public function __construct(private IConfig $config, private IAppConfig $appConfig)
16+
{
17+
}
18+
19+
public function run(): void
20+
{
21+
$this->config->getAppValue('myapp', 'mykey');
22+
$this->config->getAppValue('myapp', 'mykey', 'default');
23+
$this->config->getAppKeys('myapp');
24+
$this->config->setAppValue('myapp', 'mykey', 'value');
25+
$this->config->deleteAppValue('myapp', 'mykey');
26+
$this->config->deleteAppValues('myapp');
27+
}
28+
}
29+
30+
?>
31+
-----
32+
<?php
33+
34+
/*
35+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
36+
* SPDX-License-Identifier: AGPL-3.0-or-later
37+
*/
38+
39+
namespace Nextcloud\Rector\Test\Rector\ReplaceIConfigWithIAppConfigRector\Fixture;
40+
41+
use OCP\IAppConfig;
42+
use OCP\IConfig;
43+
44+
class SomeClass
45+
{
46+
public function __construct(private IConfig $config, private IAppConfig $appConfig)
47+
{
48+
}
49+
50+
public function run(): void
51+
{
52+
$this->appConfig->getValue('myapp', 'mykey');
53+
$this->appConfig->getValue('myapp', 'mykey', 'default');
54+
$this->appConfig->getKeys('myapp');
55+
$this->appConfig->setValue('myapp', 'mykey', 'value');
56+
$this->appConfig->deleteKey('myapp', 'mykey');
57+
$this->appConfig->deleteApp('myapp');
58+
}
59+
}
60+
61+
?>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/*
4+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
namespace Nextcloud\Rector\Test\Rector\ReplaceIConfigWithIAppConfigRector\Fixture;
9+
10+
use OCP\AppFramework\Services\IAppConfig;
11+
use OCP\IConfig;
12+
13+
class SomeClass
14+
{
15+
public function __construct(private IConfig $config, private IAppConfig $appConfig)
16+
{
17+
}
18+
19+
public function run(): void
20+
{
21+
$this->config->getAppValue('myapp', 'mykey');
22+
$this->config->getAppValue('myapp', 'mykey', 'default');
23+
$this->config->getAppKeys('myapp');
24+
$this->config->setAppValue('myapp', 'mykey', 'value');
25+
$this->config->deleteAppValue('myapp', 'mykey');
26+
$this->config->deleteAppValues('myapp');
27+
}
28+
}
29+
30+
?>
31+
-----
32+
<?php
33+
34+
/*
35+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
36+
* SPDX-License-Identifier: AGPL-3.0-or-later
37+
*/
38+
39+
namespace Nextcloud\Rector\Test\Rector\ReplaceIConfigWithIAppConfigRector\Fixture;
40+
41+
use OCP\AppFramework\Services\IAppConfig;
42+
use OCP\IConfig;
43+
44+
class SomeClass
45+
{
46+
public function __construct(private IConfig $config, private IAppConfig $appConfig, private \OCP\IAppConfig $appConfig2)
47+
{
48+
}
49+
50+
public function run(): void
51+
{
52+
$this->appConfig2->getValue('myapp', 'mykey');
53+
$this->appConfig2->getValue('myapp', 'mykey', 'default');
54+
$this->appConfig2->getKeys('myapp');
55+
$this->appConfig2->setValue('myapp', 'mykey', 'value');
56+
$this->appConfig2->deleteKey('myapp', 'mykey');
57+
$this->appConfig2->deleteApp('myapp');
58+
}
59+
}
60+
61+
?>

0 commit comments

Comments
 (0)