Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.

Commit e185a8e

Browse files
committed
feat(adr-008): add SettingsServiceTest with all branches
Adds PHPUnit coverage for SettingsService, mirroring the shape of the existing SettingsControllerTest. All 6 dependencies (IAppConfig, IAppManager, ContainerInterface, IGroupManager, IUserSession, LoggerInterface) are mocked and every method is exercised: - isOpenRegisterAvailable() — both installed and not-installed branches - getSettings() — isAdmin=true (admin user), isAdmin=false (non-admin), and the no-user/guest branch that must skip groupManager->isAdmin() - updateSettings() — persists known CONFIG_KEYS via IAppConfig, ignores unknown keys - loadConfiguration() — success path (force=true), OpenRegister-missing short-circuit, and the Throwable-caught branch per ADR-005 (logs the real exception server-side, returns a static generic message) 10 test methods / 32 assertions — well above the ADR-008 floor of >= 3 methods per logical unit. Also extends tests/bootstrap-unit.php to autoload NC core classes (OCP\IAppConfig, OCP\IRequest, etc.) without triggering OC::init(). This allows the existing SettingsControllerTest to run too (previously it failed with "Class OCP\\IRequest does not exist") so both test classes now execute: 15 tests, 49 assertions, all passing.
1 parent 95433f9 commit e185a8e

2 files changed

Lines changed: 421 additions & 10 deletions

File tree

tests/bootstrap-unit.php

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,31 @@
88
// Include Composer's autoloader.
99
require_once __DIR__ . '/../vendor/autoload.php';
1010

11-
// Bootstrap Nextcloud — since we run inside the Docker container,
12-
// the full environment (including \OC::$server) is available.
13-
if (file_exists(__DIR__ . '/../../../lib/base.php')) {
14-
require_once __DIR__ . '/../../../lib/base.php';
11+
// Register NC core autoloader (classes only — no OC::init / DB boot).
12+
//
13+
// Pure unit tests mock everything with PHPUnit createMock(), but the mock
14+
// generator still needs the target interfaces (OCP\IAppConfig, OCP\IRequest,
15+
// etc.) to be autoloadable. We point Composer's ClassLoader at NC's core
16+
// classmap if the server is reachable at one of the expected layouts.
17+
$ncRoots = [
18+
__DIR__ . '/../../..', // apps-extra/{app} next to server/lib
19+
__DIR__ . '/../../../..', // apps-extra/nested/{app}
20+
'/var/www/html', // running inside NC container
21+
];
22+
foreach ($ncRoots as $ncRoot) {
23+
if (is_file($ncRoot . '/lib/composer/autoload.php')) {
24+
require_once $ncRoot . '/lib/composer/autoload.php';
25+
break;
26+
}
1527
}
1628

17-
// Register Test\ namespace for NC test classes.
18-
$serverTestsLib = __DIR__ . '/../../../tests/lib/';
19-
if (is_dir($serverTestsLib)) {
20-
$loader = new \Composer\Autoload\ClassLoader();
21-
$loader->addPsr4('Test\\', $serverTestsLib);
22-
$loader->register(true);
29+
// Register Test\ namespace for NC test classes (used by some test bases).
30+
foreach ($ncRoots as $ncRoot) {
31+
$serverTestsLib = $ncRoot . '/tests/lib/';
32+
if (is_dir($serverTestsLib)) {
33+
$loader = new \Composer\Autoload\ClassLoader();
34+
$loader->addPsr4('Test\\', $serverTestsLib);
35+
$loader->register(true);
36+
break;
37+
}
2338
}

0 commit comments

Comments
 (0)