Skip to content

Commit 54f73ed

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 54f73ed

20 files changed

Lines changed: 32 additions & 22 deletions

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,14 @@ final class AEngineHandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
3232

3333
public function setUp(): void {
3434
$this->config = \OCP\Server::get(IConfig::class);
35-
$this->appConfig = $this->getMockAppConfig();
35+
$this->appConfig = $this->getMockAppConfigWithReset();
3636
$this->appDataFactory = \OCP\Server::get(IAppDataFactory::class);
3737
$this->dateTimeFormatter = \OCP\Server::get(IDateTimeFormatter::class);
3838
$this->tempManager = \OCP\Server::get(ITempManager::class);
3939
$this->certificatePolicyService = \OCP\Server::get(CertificatePolicyService::class);
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/Handler/CertificateEngine/CertificateEngineFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function tearDown(): void {
2828
}
2929

3030
public function setUp(): void {
31-
$this->appConfig = $this->getMockAppConfig();
31+
$this->appConfig = $this->getMockAppConfigWithReset();
3232
$this->openSslHandler = $this->createMock(OpenSslHandler::class);
3333
$this->cfsslHandler = $this->createMock(CfsslHandler::class);
3434
$this->noneHandler = $this->createMock(NoneHandler::class);

tests/php/Unit/Handler/CertificateEngine/OpenSslHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ final class OpenSslHandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
3939
private string $tempDir;
4040
public function setUp(): void {
4141
$this->config = \OCP\Server::get(IConfig::class);
42-
$this->appConfig = $this->getMockAppConfig();
42+
$this->appConfig = $this->getMockAppConfigWithReset();
4343
$this->appDataFactory = \OCP\Server::get(IAppDataFactory::class);
4444
$this->dateTimeFormatter = \OCP\Server::get(IDateTimeFormatter::class);
4545
$this->tempManager = \OCP\Server::get(ITempManager::class);

tests/php/Unit/Handler/FooterHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class FooterHandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
2727
private ITempManager $tempManager;
2828
private FooterHandler $footerHandler;
2929
public function setUp(): void {
30-
$this->appConfig = $this->getMockAppConfig();
30+
$this->appConfig = $this->getMockAppConfigWithReset();
3131
$this->pdfParserService = $this->createMock(PdfParserService::class);
3232
$this->urlGenerator = $this->createMock(IURLGenerator::class);
3333
$this->tempManager = \OCP\Server::get(ITempManager::class);

tests/php/Unit/Handler/PdfTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class PdfTest extends \OCA\Libresign\Tests\Unit\TestCase {
2424
public function setUp(): void {
2525
parent::setUp();
2626
$this->javaHelper = $this->createMock(JavaHelper::class);
27-
$this->appConfig = $this->getMockAppConfig();
27+
$this->appConfig = $this->getMockAppConfigWithReset();
2828
$this->l10n = \OCP\Server::get(IL10NFactory::class)->get(Application::APP_ID);
2929
}
3030

tests/php/Unit/Handler/SignEngine/JSignPdfHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static function setUpBeforeClass(): void {
6363
}
6464
}
6565
public function setUp(): void {
66-
$this->appConfig = $this->getMockAppConfig();
66+
$this->appConfig = $this->getMockAppConfigWithReset();
6767
$this->loggerInterface = $this->createMock(LoggerInterface::class);
6868
$this->tempManager = \OCP\Server::get(ITempManager::class);
6969
$this->signatureBackgroundService = $this->createMock(SignatureBackgroundService::class);

tests/php/Unit/Handler/SignEngine/Pkcs12HandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ final class Pkcs12HandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
3737

3838
public function setUp(): void {
3939
$this->folderService = $this->createMock(FolderService::class);
40-
$this->appConfig = $this->getMockAppConfig();
40+
$this->appConfig = $this->getMockAppConfigWithReset();
4141
$this->certificateEngineFactory = $this->createMock(CertificateEngineFactory::class);
4242
$this->l10n = \OCP\Server::get(IL10NFactory::class)->get(Application::APP_ID);
4343
$this->footerHandler = $this->createMock(FooterHandler::class);

tests/php/Unit/Helper/JavaHelperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class JavaHelperTest extends \OCA\Libresign\Tests\Unit\TestCase {
2323
public function setUp(): void {
2424
parent::setUp();
2525

26-
$this->appConfig = $this->getMockAppConfig();
26+
$this->appConfig = $this->getMockAppConfigWithReset();
2727
$this->l10n = $this->createMock(IL10N::class);
2828
$this->logger = $this->createMock(LoggerInterface::class);
2929
}

tests/php/Unit/Service/CertificatePolicyServiceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ final class CertificatePolicyServiceTest extends \OCA\Libresign\Tests\Unit\TestC
3333
public function setUp(): void {
3434
$this->appData = $this->createMock(IAppData::class);
3535
$this->urlGenerator = $this->createMock(IURLGenerator::class);
36-
$this->appConfig = $this->getMockAppConfig();
36+
$this->appConfig = $this->getMockAppConfigWithReset();
3737
$this->l10n = \OCP\Server::get(IL10NFactory::class)->get(Application::APP_ID);
3838
}
3939

tests/php/Unit/Service/FileServiceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private function getService(): FileService {
106106
$this->accountManager = $this->createMock(IAccountManager::class);
107107
$this->client = \OCP\Server::get(IClientService::class);
108108
$this->dateTimeFormatter = \OCP\Server::get(IDateTimeFormatter::class);
109-
$this->appConfig = $this->getMockAppConfig();
109+
$this->appConfig = $this->getMockAppConfigWithReset();
110110
$this->urlGenerator = \OCP\Server::get(IURLGenerator::class);
111111
$this->mimeTypeDetector = \OCP\Server::get(IMimeTypeDetector::class);
112112
$this->pkcs12Handler = \OCP\Server::get(Pkcs12Handler::class);

0 commit comments

Comments
 (0)