Skip to content

Commit c68d721

Browse files
committed
refactor: add centralized reset method for AppConfigOverwrite in tests
- Add reset() method to AppConfigOverwrite that clears both overWrite and deleted arrays and returns self - Add getMockAppConfigWithReset() wrapper in TestCase for convenient reset+return pattern - Update all test classes to use getMockAppConfigWithReset() in setUp() methods - Ensures clean state between tests without manual key-by-key deletion - Improves test isolation and prevents state pollution across test suites Signed-off-by: Vitor Mattos <[email protected]>
1 parent 3d4bdf0 commit c68d721

20 files changed

Lines changed: 35 additions & 22 deletions

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use OCA\Libresign\Handler\CertificateEngine\OpenSslHandler;
1111
use OCA\Libresign\Service\CaIdentifierService;
1212
use OCA\Libresign\Service\CertificatePolicyService;
13+
use OCA\Libresign\Tests\Unit\TestCase;
1314
use OCP\Files\AppData\IAppDataFactory;
1415
use OCP\IAppConfig;
1516
use OCP\IConfig;
@@ -32,18 +33,14 @@ final class AEngineHandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
3233

3334
public function setUp(): void {
3435
$this->config = \OCP\Server::get(IConfig::class);
35-
$this->appConfig = $this->getMockAppConfig();
36+
$this->appConfig = $this->getMockAppConfigWithReset();
3637
$this->appDataFactory = \OCP\Server::get(IAppDataFactory::class);
3738
$this->dateTimeFormatter = \OCP\Server::get(IDateTimeFormatter::class);
3839
$this->tempManager = \OCP\Server::get(ITempManager::class);
3940
$this->certificatePolicyService = \OCP\Server::get(CertificatePolicyService::class);
4041
$this->urlGenerator = \OCP\Server::get(IURLGenerator::class);
4142
$this->caIdentifierService = \OCP\Server::get(CaIdentifierService::class);
4243
$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');
4744
}
4845

4946
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use OCA\Libresign\Service\CaIdentifierService;
1515
use OCA\Libresign\Service\CertificatePolicyService;
1616
use OCA\Libresign\Service\SerialNumberService;
17+
use OCA\Libresign\Tests\Unit\TestCase;
1718
use OCP\Files\AppData\IAppDataFactory;
1819
use OCP\IAppConfig;
1920
use OCP\IConfig;
@@ -39,7 +40,7 @@ final class OpenSslHandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
3940
private string $tempDir;
4041
public function setUp(): void {
4142
$this->config = \OCP\Server::get(IConfig::class);
42-
$this->appConfig = $this->getMockAppConfig();
43+
$this->appConfig = $this->getMockAppConfigWithReset();
4344
$this->appDataFactory = \OCP\Server::get(IAppDataFactory::class);
4445
$this->dateTimeFormatter = \OCP\Server::get(IDateTimeFormatter::class);
4546
$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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use OCA\Libresign\Db\FileElement;
1414
use OCA\Libresign\Handler\CertificateEngine\CertificateEngineFactory;
1515
use OCA\Libresign\Handler\SignEngine\JSignPdfHandler;
16+
use OCA\Libresign\Tests\Unit\TestCase;
1617
use OCA\Libresign\Helper\JavaHelper;
1718
use OCA\Libresign\Service\SignatureBackgroundService;
1819
use OCA\Libresign\Service\SignatureTextService;
@@ -63,7 +64,7 @@ public static function setUpBeforeClass(): void {
6364
}
6465
}
6566
public function setUp(): void {
66-
$this->appConfig = $this->getMockAppConfig();
67+
$this->appConfig = $this->getMockAppConfigWithReset();
6768
$this->loggerInterface = $this->createMock(LoggerInterface::class);
6869
$this->tempManager = \OCP\Server::get(ITempManager::class);
6970
$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)