Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <vitor@php.rio>
  • Loading branch information
vitormattos committed Feb 1, 2024
1 parent d96c74e commit 9233d04
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 46 deletions.
2 changes: 0 additions & 2 deletions lib/Service/SignatureMethodService.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
use OCP\Accounts\IAccountManager;
use OCP\App\IAppManager;
use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IUser;
use OCP\IUserSession;
Expand All @@ -58,7 +57,6 @@ public function __construct(
private IdentifyMethodService $identifyMethodService,
private IAccountManager $accountManager,
private IAppManager $appManager,
private IConfig $config,
private IL10N $l10n,
private ISecureRandom $secureRandom,
private IHasher $hasher,
Expand Down
20 changes: 10 additions & 10 deletions tests/Unit/Handler/Pkcs12HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
use OCA\Libresign\Handler\JSignPdfHandler;
use OCA\Libresign\Handler\Pkcs12Handler;
use OCA\Libresign\Service\FolderService;
use OCP\IConfig;
use OCP\AppFramework\Services\IAppConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
use PHPUnit\Framework\MockObject\MockObject;

final class Pkcs12HandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {
protected Pkcs12Handler $pkcs12Handler;
protected FolderService|MockObject $folderService;
private IConfig|MockObject $config;
private IAppConfig|MockObject $appConfig;
private IURLGenerator|MockObject $urlGenerator;
private SystemConfig $systemConfig;
private CfsslHandler|MockObject $cfsslHandler;
Expand All @@ -27,7 +27,7 @@ final class Pkcs12HandlerTest extends \OCA\Libresign\Tests\Unit\TestCase {

public function setUp(): void {
$this->folderService = $this->createMock(FolderService::class);
$this->config = $this->createMock(IConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->systemConfig = $this->createMock(SystemConfig::class);
$this->certificateEngineHandler = $this->createMock(CertificateEngineHandler::class);
Expand All @@ -38,7 +38,7 @@ public function setUp(): void {
$this->jSignPdfHandler = $this->createMock(JSignPdfHandler::class);
$this->pkcs12Handler = new Pkcs12Handler(
$this->folderService,
$this->config,
$this->appConfig,
$this->urlGenerator,
$this->systemConfig,
$this->certificateEngineHandler,
Expand Down Expand Up @@ -90,13 +90,13 @@ public function testGetPfxOk() {
}

public function testGetFooterWithoutValidationSite() {
$this->config = $this->createMock(IConfig::class);
$this->config
$this->appConfig = $this->createMock(IAppConfig::class);
$this->appConfig
->method('getAppValue')
->willReturn(null);
$this->pkcs12Handler = new Pkcs12Handler(
$this->folderService,
$this->config,
$this->appConfig,
$this->urlGenerator,
$this->systemConfig,
$this->certificateEngineHandler,
Expand All @@ -109,8 +109,8 @@ public function testGetFooterWithoutValidationSite() {
}

public function testGetFooterWithSuccess() {
$this->config = $this->createMock(IConfig::class);
$this->config
$this->appConfig = $this->createMock(IAppConfig::class);
$this->appConfig
->method('getAppValue')
->willReturnCallback(function ($appid, $key, $default) {
switch ($key) {
Expand All @@ -124,7 +124,7 @@ public function testGetFooterWithSuccess() {
});
$this->pkcs12Handler = new Pkcs12Handler(
$this->folderService,
$this->config,
$this->appConfig,
$this->urlGenerator,
$this->systemConfig,
$this->certificateEngineHandler,
Expand Down
14 changes: 7 additions & 7 deletions tests/Unit/Helper/ValidateHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
use OCA\Libresign\Helper\ValidateHelper;
use OCA\Libresign\Service\IdentifyMethodService;
use OCA\Libresign\Service\SignatureMethodService;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IUser;
Expand All @@ -38,7 +38,7 @@ final class ValidateHelperTest extends \OCA\Libresign\Tests\Unit\TestCase {
private SignatureMethodService|MockObject $signatureMethodService;
private IMimeTypeDetector $mimeTypeDetector;
private IHasher $hasher;
private IConfig|MockObject $config;
private IAppConfig|MockObject $appConfig;
private IGroupManager|MockObject $groupManager;
private IUserManager $userManager;
private IRootFolder|MockObject $root;
Expand All @@ -60,7 +60,7 @@ public function setUp(): void {
$this->signatureMethodService = $this->createMock(SignatureMethodService::class);
$this->mimeTypeDetector = \OC::$server->get(IMimeTypeDetector::class);
$this->hasher = $this->createMock(IHasher::class);
$this->config = $this->createMock(IConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->root = $this->createMock(IRootFolder::class);
Expand All @@ -81,7 +81,7 @@ private function getValidateHelper(): ValidateHelper {
$this->signatureMethodService,
$this->mimeTypeDetector,
$this->hasher,
$this->config,
$this->appConfig,
$this->groupManager,
$this->userManager,
$this->root,
Expand Down Expand Up @@ -215,7 +215,7 @@ public function testValidateLibreSignNodeIdWhenSuccess() {
public function testCanRequestSignWithoutUserManager() {
$this->expectExceptionMessage('You are not allowed to request signing');

$this->config
$this->appConfig
->method('getAppValue')
->willReturn('');
$user = $this->createMock(\OCP\IUser::class);
Expand All @@ -225,8 +225,8 @@ public function testCanRequestSignWithoutUserManager() {
public function testCanRequestSignWithoutPermission() {
$this->expectExceptionMessage('You are not allowed to request signing');

$this->config = $this->createMock(IConfig::class);
$this->config
$this->appConfig = $this->createMock(IAppConfig::class);
$this->appConfig
->method('getAppValue')
->willReturn('["admin"]');
$this->groupManager
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/Service/AccountFileServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
use OCA\Libresign\Db\AccountFileMapper;
use OCA\Libresign\Db\File;
use OCA\Libresign\Service\AccountFileService;
use OCP\IConfig;
use OCP\AppFramework\Services\IAppConfig;
use OCP\IUser;
use PHPUnit\Framework\MockObject\MockObject;

final class AccountFileServiceTest extends \OCA\Libresign\Tests\Unit\TestCase {
private AccountFileService $service;
private AccountFileMapper|MockObject $accountFileMapper;
private IConfig $config;
private IAppConfig $appConfig;

public function setUp(): void {
$this->accountFileMapper = $this->createMock(AccountFileMapper::class);
$this->config = $this->createMock(IConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->service = new AccountFileService(
$this->accountFileMapper,
$this->config
$this->appConfig
);
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/Service/AccountServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use OCA\Libresign\Service\SignFileService;
use OCA\Settings\Mailer\NewUserMailHelper;
use OCP\Accounts\IAccountManager;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\IMimeTypeDetector;
Expand Down Expand Up @@ -50,6 +51,7 @@ final class AccountServiceTest extends \OCA\Libresign\Tests\Unit\TestCase {
private SignFileService|MockObject $signFile;
private CertificateEngineHandler|MockObject $certificateEngineHandler;
private IConfig|MockObject $config;
private IAppConfig|MockObject $appConfig;
private IMountProviderCollection|MockObject $mountProviderCollection;
private NewUserMailHelper|MockObject $newUserMail;
private IdentifyMethodService|MockObject $identifyMethodService;
Expand Down Expand Up @@ -83,6 +85,7 @@ public function setUp(): void {
$this->requestSignatureService = $this->createMock(RequestSignatureService::class);
$this->certificateEngineHandler = $this->createMock(CertificateEngineHandler::class);
$this->config = $this->createMock(IConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->mountProviderCollection = $this->createMock(IMountProviderCollection::class);
$this->newUserMail = $this->createMock(NewUserMailHelper::class);
$this->identifyMethodService = $this->createMock(IdentifyMethodService::class);
Expand Down Expand Up @@ -113,6 +116,7 @@ private function getService(): AccountService {
$this->requestSignatureService,
$this->certificateEngineHandler,
$this->config,
$this->appConfig,
$this->mountProviderCollection,
$this->newUserMail,
$this->identifyMethodService,
Expand Down
10 changes: 5 additions & 5 deletions tests/Unit/Service/FolderServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace OCA\Libresign\Tests\Unit\Service;

use OCA\Libresign\Service\FolderService;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Files\AppData\IAppDataFactory;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IL10N;

final class FolderServiceTest extends \OCA\Libresign\Tests\Unit\TestCase {
Expand All @@ -21,14 +21,14 @@ public function testGetFolderWithInvalidNodeId() {
->method('getMountsForFileId')
->willreturn([]);
$appDataFactory = $this->createMock(IAppDataFactory::class);
$config = $this->createMock(IConfig::class);
$appConfig = $this->createMock(IAppConfig::class);
$l10n = $this->createMock(IL10N::class);

$service = new FolderService(
$root,
$userMountCache,
$appDataFactory,
$config,
$appConfig,
$l10n,
171
);
Expand All @@ -49,14 +49,14 @@ public function testGetFolderWithValidNodeId() {
$root->method('getById')
->willReturn([$node]);
$appDataFactory = $this->createMock(IAppDataFactory::class);
$config = $this->createMock(IConfig::class);
$appConfig = $this->createMock(IAppConfig::class);
$l10n = $this->createMock(IL10N::class);

$service = new FolderService(
$root,
$userMountCache,
$appDataFactory,
$config,
$appConfig,
$l10n,
1
);
Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/Service/InstallServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use OCA\Libresign\Handler\CertificateEngine\Handler as CertificateEngineHandler;
use OCA\Libresign\Service\InstallService;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Files\AppData\IAppDataFactory;
use OCP\Files\IRootFolder;
use OCP\Http\Client\IClientService;
Expand All @@ -40,6 +41,7 @@ final class InstallServiceTest extends \OCA\Libresign\Tests\Unit\TestCase {
private IClientService|MockObject $clientService;
private CertificateEngineHandler|MockObject $certificateEngineHandler;
private IConfig|MockObject $config;
private IAppConfig|MockObject $appConfig;
private IRootFolder|MockObject $rootFolder;
private LoggerInterface|MockObject $logger;
private IAppDataFactory|MockObject $appDataFactory;
Expand All @@ -53,6 +55,7 @@ protected function getInstallService(): InstallService {
$this->clientService = $this->createMock(IClientService::class);
$this->certificateEngineHandler = $this->createMock(CertificateEngineHandler::class);
$this->config = $this->createMock(IConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->rootFolder = $this->createMock(IRootFolder::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->appDataFactory = $this->createMock(IAppDataFactory::class);
Expand All @@ -61,6 +64,7 @@ protected function getInstallService(): InstallService {
$this->clientService,
$this->certificateEngineHandler,
$this->config,
$this->appConfig,
$this->rootFolder,
$this->logger,
$this->appDataFactory
Expand Down
14 changes: 7 additions & 7 deletions tests/Unit/Service/MailServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use OCA\Libresign\Db\FileMapper;
use OCA\Libresign\Db\SignRequest;
use OCA\Libresign\Service\MailService;
use OCP\IConfig;
use OCP\AppFramework\Services\IAppConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Mail\IMailer;
Expand All @@ -23,7 +23,7 @@ final class MailServiceTest extends \OCA\Libresign\Tests\Unit\TestCase {
private FileMapper|MockObject $fileMapper;
private IL10N|MockObject $l10n;
private IURLGenerator|MockObject $urlGenerator;
private IConfig|MockObject $config;
private IAppConfig|MockObject $appConfig;
private MailService $service;

public function setUp(): void {
Expand All @@ -36,14 +36,14 @@ public function setUp(): void {
->method('t')
->will($this->returnArgument(0));
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->config = $this->createMock(IConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->service = new MailService(
$this->logger,
$this->mailer,
$this->fileMapper,
$this->l10n,
$this->urlGenerator,
$this->config
$this->appConfig
);
}

Expand All @@ -59,7 +59,7 @@ public function testSuccessNotifyUnsignedUser() {
['getUuid', [], 'asdfg'],
['getFileId', [], 1]
]));

$file = $this->createMock(File::class);
$file
->method('__call')
Expand All @@ -68,7 +68,7 @@ public function testSuccessNotifyUnsignedUser() {
$this->fileMapper
->method('getById')
->will($this->returnValue($file));
$this->config
$this->appConfig
->method('getAppValue')
->willReturn(true);
$actual = $this->service->notifyUnsignedUser($signRequest, 'a@b.coop');
Expand Down Expand Up @@ -103,7 +103,7 @@ public function testFailToSendMailToUnsignedUser() {
->willReturnCallback(function () {
throw new \Exception("Error Processing Request", 1);
});
$this->config
$this->appConfig
->method('getAppValue')
->will($this->returnValue(true));
$actual = $this->service->notifyUnsignedUser($signRequest, 'a@b.coop');
Expand Down
3 changes: 0 additions & 3 deletions tests/Unit/Service/RequestSignatureServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IUser;
use OCP\IUserManager;
Expand All @@ -53,7 +52,6 @@ final class RequestSignatureServiceTest extends \OCA\Libresign\Tests\Unit\TestCa
private IClientService|MockObject $clientService;
private IUserManager|MockObject $userManager;
private FolderService|MockObject $folderService;
private IConfig $config;
private ValidateHelper|MockObject $validateHelper;
private FileElementMapper|MockObject $fileElementMapper;
private FileElementService|MockObject $fileElementService;
Expand All @@ -77,7 +75,6 @@ public function setUp(): void {
$this->clientService = $this->createMock(IClientService::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->folderService = $this->createMock(FolderService::class);
$this->config = $this->createMock(IConfig::class);
$this->validateHelper = $this->createMock(ValidateHelper::class);
$this->fileElementMapper = $this->createMock(FileElementMapper::class);
$this->fileElementService = $this->createMock(FileElementService::class);
Expand Down
Loading

0 comments on commit 9233d04

Please sign in to comment.