Skip to content

Commit 139f8a6

Browse files
committed
refactor: add centralized reset in getMockAppConfig for test isolation
- Add reset() method to AppConfigOverwrite that clears overWrite and deleted arrays and returns self - Integrate reset() directly into getMockAppConfig() to ensure clean state on every call - All tests now automatically get clean AppConfig state without explicit reset calls - Prevents state pollution across test suites by resetting at the source - Simplifies test code by removing need for separate reset wrapper method Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 3d4bdf0 commit 139f8a6

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

tests/php/Unit/Handler/CertificateEngine/AEngineHandlerTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ public function setUp(): void {
4040
$this->urlGenerator = \OCP\Server::get(IURLGenerator::class);
4141
$this->caIdentifierService = \OCP\Server::get(CaIdentifierService::class);
4242
$this->logger = \OCP\Server::get(LoggerInterface::class);
43-
44-
$this->appConfig->deleteKey(Application::APP_ID, 'certificate_engine');
45-
$this->appConfig->deleteKey(Application::APP_ID, 'identify_methods');
46-
$this->appConfig->deleteKey(Application::APP_ID, 'config_path');
4743
}
4844

4945
private function getInstance(): OpenSslHandler {

tests/php/Unit/TestCase.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ public static function getMockAppConfig(): IAppConfig {
7979
));
8080
$service = \OCP\Server::get(\OCP\IAppConfig::class);
8181
}
82+
if ($service instanceof AppConfigOverwrite) {
83+
$service->reset();
84+
}
8285
return $service;
8386
}
8487

tests/php/lib/AppConfigOverwrite.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ public function deleteKey(string $app, string $key): void {
138138
$this->markDeleted($app, $key);
139139
}
140140

141+
public function reset(): self {
142+
$this->overWrite = [];
143+
$this->deleted = [];
144+
return $this;
145+
}
146+
141147
private function isDeleted(string $app, string $key): bool {
142148
return isset($this->deleted[$app][$key]);
143149
}

0 commit comments

Comments
 (0)