mirror of
https://github.com/LibreSign/libresign.git
synced 2025-12-17 21:12:16 +01:00
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>
This commit is contained in:
parent
3d4bdf0294
commit
54f73ed475
20 changed files with 32 additions and 22 deletions
|
|
@ -32,7 +32,7 @@ final class AEngineHandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
|
|||
|
||||
public function setUp(): void {
|
||||
$this->config = \OCP\Server::get(IConfig::class);
|
||||
$this->appConfig = $this->getMockAppConfig();
|
||||
$this->appConfig = $this->getMockAppConfigWithReset();
|
||||
$this->appDataFactory = \OCP\Server::get(IAppDataFactory::class);
|
||||
$this->dateTimeFormatter = \OCP\Server::get(IDateTimeFormatter::class);
|
||||
$this->tempManager = \OCP\Server::get(ITempManager::class);
|
||||
|
|
@ -40,10 +40,6 @@ final class AEngineHandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
|
|||
$this->urlGenerator = \OCP\Server::get(IURLGenerator::class);
|
||||
$this->caIdentifierService = \OCP\Server::get(CaIdentifierService::class);
|
||||
$this->logger = \OCP\Server::get(LoggerInterface::class);
|
||||
|
||||
$this->appConfig->deleteKey(Application::APP_ID, 'certificate_engine');
|
||||
$this->appConfig->deleteKey(Application::APP_ID, 'identify_methods');
|
||||
$this->appConfig->deleteKey(Application::APP_ID, 'config_path');
|
||||
}
|
||||
|
||||
private function getInstance(): OpenSslHandler {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class CertificateEngineFactoryTest extends \OCA\Libresign\Tests\Unit\TestCase {
|
|||
}
|
||||
|
||||
public function setUp(): void {
|
||||
$this->appConfig = $this->getMockAppConfig();
|
||||
$this->appConfig = $this->getMockAppConfigWithReset();
|
||||
$this->openSslHandler = $this->createMock(OpenSslHandler::class);
|
||||
$this->cfsslHandler = $this->createMock(CfsslHandler::class);
|
||||
$this->noneHandler = $this->createMock(NoneHandler::class);
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ final class OpenSslHandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
|
|||
private string $tempDir;
|
||||
public function setUp(): void {
|
||||
$this->config = \OCP\Server::get(IConfig::class);
|
||||
$this->appConfig = $this->getMockAppConfig();
|
||||
$this->appConfig = $this->getMockAppConfigWithReset();
|
||||
$this->appDataFactory = \OCP\Server::get(IAppDataFactory::class);
|
||||
$this->dateTimeFormatter = \OCP\Server::get(IDateTimeFormatter::class);
|
||||
$this->tempManager = \OCP\Server::get(ITempManager::class);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ final class FooterHandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
|
|||
private ITempManager $tempManager;
|
||||
private FooterHandler $footerHandler;
|
||||
public function setUp(): void {
|
||||
$this->appConfig = $this->getMockAppConfig();
|
||||
$this->appConfig = $this->getMockAppConfigWithReset();
|
||||
$this->pdfParserService = $this->createMock(PdfParserService::class);
|
||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
$this->tempManager = \OCP\Server::get(ITempManager::class);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ final class PdfTest extends \OCA\Libresign\Tests\Unit\TestCase {
|
|||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->javaHelper = $this->createMock(JavaHelper::class);
|
||||
$this->appConfig = $this->getMockAppConfig();
|
||||
$this->appConfig = $this->getMockAppConfigWithReset();
|
||||
$this->l10n = \OCP\Server::get(IL10NFactory::class)->get(Application::APP_ID);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ final class JSignPdfHandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
|
|||
}
|
||||
}
|
||||
public function setUp(): void {
|
||||
$this->appConfig = $this->getMockAppConfig();
|
||||
$this->appConfig = $this->getMockAppConfigWithReset();
|
||||
$this->loggerInterface = $this->createMock(LoggerInterface::class);
|
||||
$this->tempManager = \OCP\Server::get(ITempManager::class);
|
||||
$this->signatureBackgroundService = $this->createMock(SignatureBackgroundService::class);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ final class Pkcs12HandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
|
|||
|
||||
public function setUp(): void {
|
||||
$this->folderService = $this->createMock(FolderService::class);
|
||||
$this->appConfig = $this->getMockAppConfig();
|
||||
$this->appConfig = $this->getMockAppConfigWithReset();
|
||||
$this->certificateEngineFactory = $this->createMock(CertificateEngineFactory::class);
|
||||
$this->l10n = \OCP\Server::get(IL10NFactory::class)->get(Application::APP_ID);
|
||||
$this->footerHandler = $this->createMock(FooterHandler::class);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class JavaHelperTest extends \OCA\Libresign\Tests\Unit\TestCase {
|
|||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->appConfig = $this->getMockAppConfig();
|
||||
$this->appConfig = $this->getMockAppConfigWithReset();
|
||||
$this->l10n = $this->createMock(IL10N::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ final class CertificatePolicyServiceTest extends \OCA\Libresign\Tests\Unit\TestC
|
|||
public function setUp(): void {
|
||||
$this->appData = $this->createMock(IAppData::class);
|
||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
$this->appConfig = $this->getMockAppConfig();
|
||||
$this->appConfig = $this->getMockAppConfigWithReset();
|
||||
$this->l10n = \OCP\Server::get(IL10NFactory::class)->get(Application::APP_ID);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ final class FileServiceTest extends \OCA\Libresign\Tests\Unit\TestCase {
|
|||
$this->accountManager = $this->createMock(IAccountManager::class);
|
||||
$this->client = \OCP\Server::get(IClientService::class);
|
||||
$this->dateTimeFormatter = \OCP\Server::get(IDateTimeFormatter::class);
|
||||
$this->appConfig = $this->getMockAppConfig();
|
||||
$this->appConfig = $this->getMockAppConfigWithReset();
|
||||
$this->urlGenerator = \OCP\Server::get(IURLGenerator::class);
|
||||
$this->mimeTypeDetector = \OCP\Server::get(IMimeTypeDetector::class);
|
||||
$this->pkcs12Handler = \OCP\Server::get(Pkcs12Handler::class);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class FooterServiceTest extends TestCase {
|
|||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->appConfig = $this->getMockAppConfig();
|
||||
$this->appConfig = $this->getMockAppConfigWithReset();
|
||||
$this->footerHandler = $this->createMock(FooterHandler::class);
|
||||
$this->service = new FooterService($this->appConfig, $this->footerHandler);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ final class PasswordTest extends \OCA\Libresign\Tests\Unit\TestCase {
|
|||
|
||||
public function setUp(): void {
|
||||
$this->identifyService = $this->createMock(IdentifyService::class);
|
||||
$this->appConfig = $this->getMockAppConfig();
|
||||
$this->appConfig = $this->getMockAppConfigWithReset();
|
||||
$this->folderService = $this->createMock(FolderService::class);
|
||||
$this->certificateEngineFactory = $this->createMock(CertificateEngineFactory::class);
|
||||
$this->l10n = \OCP\Server::get(IL10NFactory::class)->get(Application::APP_ID);
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ final class ConfigureCheckServiceTest extends \OCA\Libresign\Tests\Unit\TestCase
|
|||
|
||||
public function setUp(): void {
|
||||
self::$mockExtensionLoaded = [];
|
||||
$this->appConfig = $this->getMockAppConfig();
|
||||
$this->appConfig = $this->getMockAppConfigWithReset();
|
||||
$this->systemConfig = $this->createMock(SystemConfig::class);
|
||||
$this->ocAppConfig = $this->createMock(AppConfig::class);
|
||||
$this->appManager = $this->createMock(IAppManager::class);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ final class SignSetupServiceTest extends \OCA\Libresign\Tests\Unit\TestCase {
|
|||
$this->fileAccessHelper = new FileAccessHelper();
|
||||
$this->appManager = $this->createMock(IAppManager::class);
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$this->appConfig = $this->getMockAppConfig();
|
||||
$this->appConfig = $this->getMockAppConfigWithReset();
|
||||
$this->appDataFactory = \OCP\Server::get(IAppDataFactory::class);
|
||||
$this->tempManager = \OCP\Server::get(ITempManager::class);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ final class ReminderServiceTest extends \OCA\Libresign\Tests\Unit\TestCase {
|
|||
|
||||
public function setUp(): void {
|
||||
$this->jobList = $this->createMock(IJobList::class);
|
||||
$this->appConfig = $this->getMockAppConfig();
|
||||
$this->appConfig = $this->getMockAppConfigWithReset();
|
||||
$this->dateTimeZone = Server::get(IDateTimeZone::class);
|
||||
$this->time = $this->createMock(ITimeFactory::class);
|
||||
$this->signRequestMapper = $this->createMock(SignRequestMapper::class);
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ final class SignFileServiceTest extends \OCA\Libresign\Tests\Unit\TestCase {
|
|||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->folderService = $this->createMock(FolderService::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->appConfig = $this->getMockAppConfig();
|
||||
$this->appConfig = $this->getMockAppConfigWithReset();
|
||||
$this->validateHelper = $this->createMock(\OCA\Libresign\Helper\ValidateHelper::class);
|
||||
$this->signerElementsService = $this->createMock(SignerElementsService::class);
|
||||
$this->root = $this->createMock(\OCP\Files\IRootFolder::class);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ final class SignatureBackgroundServiceTest extends \OCA\Libresign\Tests\Unit\Tes
|
|||
|
||||
public function setUp(): void {
|
||||
$this->appData = $this->createMock(IAppData::class);
|
||||
$this->appConfig = $this->getMockAppConfig();
|
||||
$this->appConfig = $this->getMockAppConfigWithReset();
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$this->tempManager = $this->createMock(ITempManager::class);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ final class SignatureTextServiceTest extends \OCA\Libresign\Tests\Unit\TestCase
|
|||
|
||||
public function setUp(): void {
|
||||
$this->l10n = \OCP\Server::get(IL10NFactory::class)->get(Application::APP_ID);
|
||||
$this->appConfig = $this->getMockAppConfig();
|
||||
$this->appConfig = $this->getMockAppConfigWithReset();
|
||||
$this->dateTimeZone = \OCP\Server::get(IDateTimeZone::class);
|
||||
$this->request = $this->createMock(IRequest::class);
|
||||
$this->userSession = $this->createMock(IUserSession::class);
|
||||
|
|
|
|||
|
|
@ -82,6 +82,14 @@ class TestCase extends \Test\TestCase {
|
|||
return $service;
|
||||
}
|
||||
|
||||
public static function getMockAppConfigWithReset(): IAppConfig {
|
||||
$appConfig = self::getMockAppConfig();
|
||||
if ($appConfig instanceof AppConfigOverwrite) {
|
||||
$appConfig->reset();
|
||||
}
|
||||
return $appConfig;
|
||||
}
|
||||
|
||||
public function mockConfig($config):void {
|
||||
$service = \OCP\Server::get(\OCP\IConfig::class);
|
||||
if (!$service instanceof AllConfigOverwrite) {
|
||||
|
|
|
|||
|
|
@ -138,6 +138,12 @@ class AppConfigOverwrite extends AppConfig {
|
|||
$this->markDeleted($app, $key);
|
||||
}
|
||||
|
||||
public function reset(): self {
|
||||
$this->overWrite = [];
|
||||
$this->deleted = [];
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function isDeleted(string $app, string $key): bool {
|
||||
return isset($this->deleted[$app][$key]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue