Skip to content

Commit bbc9ed1

Browse files
committed
fix(config): fix tests+psalm
Signed-off-by: Maxence Lange <[email protected]>
1 parent a4b9edc commit bbc9ed1

File tree

10 files changed

+46
-29
lines changed

10 files changed

+46
-29
lines changed

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,7 @@
12191219
'OC\\Comments\\ManagerFactory' => $baseDir . '/lib/private/Comments/ManagerFactory.php',
12201220
'OC\\Config' => $baseDir . '/lib/private/Config.php',
12211221
'OC\\Config\\ConfigManager' => $baseDir . '/lib/private/Config/ConfigManager.php',
1222+
'OC\\Config\\PresetManager' => $baseDir . '/lib/private/Config/PresetManager.php',
12221223
'OC\\Config\\UserConfig' => $baseDir . '/lib/private/Config/UserConfig.php',
12231224
'OC\\Console\\Application' => $baseDir . '/lib/private/Console/Application.php',
12241225
'OC\\Console\\TimestampFormatter' => $baseDir . '/lib/private/Console/TimestampFormatter.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
12601260
'OC\\Comments\\ManagerFactory' => __DIR__ . '/../../..' . '/lib/private/Comments/ManagerFactory.php',
12611261
'OC\\Config' => __DIR__ . '/../../..' . '/lib/private/Config.php',
12621262
'OC\\Config\\ConfigManager' => __DIR__ . '/../../..' . '/lib/private/Config/ConfigManager.php',
1263+
'OC\\Config\\PresetManager' => __DIR__ . '/../../..' . '/lib/private/Config/PresetManager.php',
12631264
'OC\\Config\\UserConfig' => __DIR__ . '/../../..' . '/lib/private/Config/UserConfig.php',
12641265
'OC\\Console\\Application' => __DIR__ . '/../../..' . '/lib/private/Console/Application.php',
12651266
'OC\\Console\\TimestampFormatter' => __DIR__ . '/../../..' . '/lib/private/Console/TimestampFormatter.php',

lib/private/AppConfig.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use OC\Config\PresetManager;
1717
use OCP\Config\Lexicon\Entry;
1818
use OCP\Config\Lexicon\ILexicon;
19-
use OCP\Config\Lexicon\Preset;
2019
use OCP\Config\Lexicon\Strictness;
2120
use OCP\Config\ValueType;
2221
use OCP\DB\Exception as DBException;
@@ -28,7 +27,6 @@
2827
use OCP\IConfig;
2928
use OCP\IDBConnection;
3029
use OCP\Security\ICrypto;
31-
use OCP\Server;
3230
use Psr\Log\LoggerInterface;
3331

3432
/**
@@ -1136,7 +1134,7 @@ public function getKeyDetails(string $app, string $key): array {
11361134
]);
11371135
}
11381136

1139-
return array_filter($details, static fn($v): bool => ($v !== null));
1137+
return array_filter($details, static fn ($v): bool => ($v !== null));
11401138
}
11411139

11421140
/**

lib/private/Config/ConfigManager.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
use OCP\Config\Exceptions\TypeConflictException;
1515
use OCP\Config\IUserConfig;
1616
use OCP\Config\Lexicon\Entry;
17-
use OCP\Config\Lexicon\Preset;
1817
use OCP\Config\ValueType;
1918
use OCP\IAppConfig;
20-
use OCP\IConfig;
2119
use OCP\Server;
2220
use Psr\Log\LoggerInterface;
2321

lib/private/Config/PresetManager.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
/**
1515
* tools to maintains configurations
16-
*
17-
* @since 32.0.0
1816
*/
1917
class PresetManager {
2018
private const PRESET_CONFIGKEY = 'config_preset';
@@ -37,6 +35,9 @@ public function setLexiconPreset(Preset $preset): void {
3735
$this->configManager->clearConfigCaches();
3836
}
3937

38+
/**
39+
* returns currently selected Preset
40+
*/
4041
public function getLexiconPreset(): Preset {
4142
if ($this->configLexiconPreset === null) {
4243
$this->configLexiconPreset = Preset::tryFrom($this->config->getSystemValueInt(self::PRESET_CONFIGKEY, 0)) ?? Preset::NONE;

lib/private/Config/UserConfig.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use OCP\Config\IUserConfig;
1919
use OCP\Config\Lexicon\Entry;
2020
use OCP\Config\Lexicon\ILexicon;
21-
use OCP\Config\Lexicon\Preset;
2221
use OCP\Config\Lexicon\Strictness;
2322
use OCP\Config\ValueType;
2423
use OCP\DB\Exception as DBException;
@@ -27,7 +26,6 @@
2726
use OCP\IConfig;
2827
use OCP\IDBConnection;
2928
use OCP\Security\ICrypto;
30-
use OCP\Server;
3129
use Psr\Log\LoggerInterface;
3230

3331
/**

lib/private/Profile/ProfileManager.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -327,22 +327,23 @@ private function getDefaultProfileConfig(IUser $targetUser, ?IUser $visitingUser
327327

328328
/**
329329
* modify property visibility, based on current Preset
330+
*
331+
* @psalm-suppress UnhandledMatchCondition if conditions are not met, we do not change $visibility
330332
*/
331333
private function applyDefaultProfilePreset(string $property, string &$visibility): void {
332-
$overwrite = match($this->presetManager->getLexiconPreset()) {
333-
Preset::SHARED, Preset::SCHOOL, Preset::UNIVERSITY => match($property) {
334-
IAccountManager::PROPERTY_ADDRESS, IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_PHONE => self::VISIBILITY_HIDE,
335-
},
336-
Preset::PRIVATE, Preset::FAMILY, Preset::CLUB => match($property) {
337-
IAccountManager::PROPERTY_EMAIL => self::VISIBILITY_SHOW,
338-
},
339-
Preset::SMALL, Preset::MEDIUM, Preset::LARGE => match($property) {
340-
IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_PHONE => self::VISIBILITY_SHOW,
341-
},
342-
default => null,
343-
};
344-
345-
if ($overwrite === null) {
334+
try {
335+
$overwrite = match ($this->presetManager->getLexiconPreset()) {
336+
Preset::SHARED, Preset::SCHOOL, Preset::UNIVERSITY => match ($property) {
337+
IAccountManager::PROPERTY_ADDRESS, IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_PHONE => self::VISIBILITY_HIDE,
338+
},
339+
Preset::PRIVATE, Preset::FAMILY, Preset::CLUB => match ($property) {
340+
IAccountManager::PROPERTY_EMAIL => self::VISIBILITY_SHOW,
341+
},
342+
Preset::SMALL, Preset::MEDIUM, Preset::LARGE => match ($property) {
343+
IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_PHONE => self::VISIBILITY_SHOW,
344+
},
345+
};
346+
} catch (\UnhandledMatchError) {
346347
return;
347348
}
348349

tests/lib/AppConfigTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
use InvalidArgumentException;
1111
use OC\AppConfig;
12+
use OC\Config\ConfigManager;
13+
use OC\Config\PresetManager;
1214
use OCP\Exceptions\AppConfigTypeConflictException;
1315
use OCP\Exceptions\AppConfigUnknownKeyException;
1416
use OCP\IAppConfig;
@@ -29,6 +31,8 @@ class AppConfigTest extends TestCase {
2931
protected IAppConfig $appConfig;
3032
protected IDBConnection $connection;
3133
private IConfig $config;
34+
private ConfigManager $configManager;
35+
private PresetManager $presetManager;
3236
private LoggerInterface $logger;
3337
private ICrypto $crypto;
3438

@@ -99,6 +103,8 @@ protected function setUp(): void {
99103

100104
$this->connection = Server::get(IDBConnection::class);
101105
$this->config = Server::get(IConfig::class);
106+
$this->configManager = Server::get(ConfigManager::class);
107+
$this->presetManager = Server::get(PresetManager::class);
102108
$this->logger = Server::get(LoggerInterface::class);
103109
$this->crypto = Server::get(ICrypto::class);
104110

@@ -190,6 +196,8 @@ private function generateAppConfig(bool $preLoading = true): IAppConfig {
190196
$config = new AppConfig(
191197
$this->connection,
192198
$this->config,
199+
$this->configManager,
200+
$this->presetManager,
193201
$this->logger,
194202
$this->crypto,
195203
);

tests/lib/Config/LexiconTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use OC\AppConfig;
1111
use OC\AppFramework\Bootstrap\Coordinator;
1212
use OC\Config\ConfigManager;
13+
use OC\Config\PresetManager;
1314
use OCP\Config\Exceptions\TypeConflictException;
1415
use OCP\Config\Exceptions\UnknownKeyException;
1516
use OCP\Config\IUserConfig;
@@ -32,6 +33,7 @@ class LexiconTest extends TestCase {
3233
private IAppConfig $appConfig;
3334
private IUserConfig $userConfig;
3435
private ConfigManager $configManager;
36+
private PresetManager $presetManager;
3537

3638
protected function setUp(): void {
3739
parent::setUp();
@@ -45,6 +47,7 @@ protected function setUp(): void {
4547
$this->appConfig = Server::get(IAppConfig::class);
4648
$this->userConfig = Server::get(IUserConfig::class);
4749
$this->configManager = Server::get(ConfigManager::class);
50+
$this->presetManager = Server::get(PresetManager::class);
4851
}
4952

5053
protected function tearDown(): void {
@@ -206,26 +209,26 @@ public function testAppConfigLexiconRenameInvertBoolean() {
206209
}
207210

208211
public function testAppConfigLexiconPreset() {
209-
$this->configManager->setLexiconPreset(Preset::FAMILY);
212+
$this->presetManager->setLexiconPreset(Preset::FAMILY);
210213
$this->assertSame('family', $this->appConfig->getValueString(TestLexicon_E::APPID, 'key3'));
211214
}
212215

213216
public function testAppConfigLexiconPresets() {
214-
$this->configManager->setLexiconPreset(Preset::MEDIUM);
217+
$this->presetManager->setLexiconPreset(Preset::MEDIUM);
215218
$this->assertSame('club+medium', $this->appConfig->getValueString(TestLexicon_E::APPID, 'key3'));
216-
$this->configManager->setLexiconPreset(Preset::FAMILY);
219+
$this->presetManager->setLexiconPreset(Preset::FAMILY);
217220
$this->assertSame('family', $this->appConfig->getValueString(TestLexicon_E::APPID, 'key3'));
218221
}
219222

220223
public function testUserConfigLexiconPreset() {
221-
$this->configManager->setLexiconPreset(Preset::FAMILY);
224+
$this->presetManager->setLexiconPreset(Preset::FAMILY);
222225
$this->assertSame('family', $this->userConfig->getValueString('user1', TestLexicon_E::APPID, 'key3'));
223226
}
224227

225228
public function testUserConfigLexiconPresets() {
226-
$this->configManager->setLexiconPreset(Preset::MEDIUM);
229+
$this->presetManager->setLexiconPreset(Preset::MEDIUM);
227230
$this->assertSame('club+medium', $this->userConfig->getValueString('user1', TestLexicon_E::APPID, 'key3'));
228-
$this->configManager->setLexiconPreset(Preset::FAMILY);
231+
$this->presetManager->setLexiconPreset(Preset::FAMILY);
229232
$this->assertSame('family', $this->userConfig->getValueString('user1', TestLexicon_E::APPID, 'key3'));
230233
}
231234
}

tests/lib/Config/UserConfigTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*/
88
namespace Test\lib\Config;
99

10+
use OC\Config\ConfigManager;
11+
use OC\Config\PresetManager;
1012
use OC\Config\UserConfig;
1113
use OCP\Config\Exceptions\TypeConflictException;
1214
use OCP\Config\Exceptions\UnknownKeyException;
@@ -29,6 +31,8 @@
2931
class UserConfigTest extends TestCase {
3032
protected IDBConnection $connection;
3133
private IConfig $config;
34+
private ConfigManager $configManager;
35+
private PresetManager $presetManager;
3236
private LoggerInterface $logger;
3337
private ICrypto $crypto;
3438
private array $originalPreferences;
@@ -173,6 +177,8 @@ protected function setUp(): void {
173177

174178
$this->connection = Server::get(IDBConnection::class);
175179
$this->config = Server::get(IConfig::class);
180+
$this->configManager = Server::get(ConfigManager::class);
181+
$this->presetManager = Server::get(PresetManager::class);
176182
$this->logger = Server::get(LoggerInterface::class);
177183
$this->crypto = Server::get(ICrypto::class);
178184

@@ -282,6 +288,8 @@ private function generateUserConfig(array $preLoading = []): IUserConfig {
282288
$userConfig = new UserConfig(
283289
$this->connection,
284290
$this->config,
291+
$this->configManager,
292+
$this->presetManager,
285293
$this->logger,
286294
$this->crypto,
287295
);

0 commit comments

Comments
 (0)