From a6d1ce387ab4ee0528a2c3c9b649cf0d41aebe99 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Sun, 12 Jan 2025 15:34:38 -0300 Subject: [PATCH] fix: unit tests and linter Signed-off-by: Vitor Mattos --- tests/Api/Controller/FileControllerTest.php | 2 +- tests/Unit/Handler/FooterHandlerTest.php | 2 +- tests/Unit/Handler/Pkcs12HandlerTest.php | 8 +++----- .../Service/Install/SignSetupServiceTest.php | 3 ++- tests/Unit/TestCase.php | 16 ++++++---------- 5 files changed, 13 insertions(+), 18 deletions(-) diff --git a/tests/Api/Controller/FileControllerTest.php b/tests/Api/Controller/FileControllerTest.php index e4986e991..f33dd7e4f 100644 --- a/tests/Api/Controller/FileControllerTest.php +++ b/tests/Api/Controller/FileControllerTest.php @@ -16,7 +16,7 @@ final class FileControllerTest extends ApiTestCase { * @runInSeparateProcess */ public function testValidateUsignUuidWithInvalidData() { - $this->mockAppConfig([]); + $this->getMockAppConfig([]); $this->request ->withPath('/api/v1/file/validate/uuid/invalid') diff --git a/tests/Unit/Handler/FooterHandlerTest.php b/tests/Unit/Handler/FooterHandlerTest.php index e02d988e1..cd73261e8 100644 --- a/tests/Unit/Handler/FooterHandlerTest.php +++ b/tests/Unit/Handler/FooterHandlerTest.php @@ -12,7 +12,7 @@ use PHPUnit\Framework\MockObject\MockObject; final class FooterHandlerTest extends \OCA\Libresign\Tests\Unit\TestCase { - private IAppConfig|MockObject $appConfig; + private IAppConfig $appConfig; private PdfParserService|MockObject $pdfParserService; private IURLGenerator|MockObject $urlGenerator; private IL10N|MockObject $l10n; diff --git a/tests/Unit/Handler/Pkcs12HandlerTest.php b/tests/Unit/Handler/Pkcs12HandlerTest.php index d71f3832d..e3bb68a76 100644 --- a/tests/Unit/Handler/Pkcs12HandlerTest.php +++ b/tests/Unit/Handler/Pkcs12HandlerTest.php @@ -19,15 +19,13 @@ final class Pkcs12HandlerTest extends \OCA\Libresign\Tests\Unit\TestCase { protected Pkcs12Handler $pkcs12Handler; protected FolderService|MockObject $folderService; - private IAppConfig|MockObject $appConfig; + private IAppConfig $appConfig; private SystemConfig $systemConfig; - private CfsslHandler|MockObject $cfsslHandler; - private IL10N|MockObject $l10n; + private IL10N $l10n; private JSignPdfHandler|MockObject $jSignPdfHandler; private FooterHandler|MockObject $footerHandler; - private ITempManager|MockObject $tempManager; + private ITempManager $tempManager; private CertificateEngineHandler|MockObject $certificateEngineHandler; - private array $cfsslHandlerBuffer = []; public function setUp(): void { $this->folderService = $this->createMock(FolderService::class); diff --git a/tests/Unit/Service/Install/SignSetupServiceTest.php b/tests/Unit/Service/Install/SignSetupServiceTest.php index 64e53218d..466197d67 100644 --- a/tests/Unit/Service/Install/SignSetupServiceTest.php +++ b/tests/Unit/Service/Install/SignSetupServiceTest.php @@ -26,8 +26,9 @@ final class SignSetupServiceTest extends \OCA\Libresign\Tests\Unit\TestCase { private EnvironmentHelper|MockObject $environmentHelper; private FileAccessHelper $fileAccessHelper; private IConfig|MockObject $config; - private IAppConfig|MockObject $appConfig; + private IAppConfig $appConfig; private IAppManager|MockObject $appManager; + private IAppDataFactory $appDataFactory; public function setUp(): void { $this->environmentHelper = $this->createMock(EnvironmentHelper::class); diff --git a/tests/Unit/TestCase.php b/tests/Unit/TestCase.php index e88c856ae..a2e319980 100644 --- a/tests/Unit/TestCase.php +++ b/tests/Unit/TestCase.php @@ -23,11 +23,11 @@ class TestCase extends \Test\TestCase { private signRequestMapper $signRequestMapper; private array $users = []; - public function mockAppConfig($config) { + public function getMockAppConfig(): IAppConfig { \OC::$server->registerParameter('appName', 'libresign'); $service = \OCP\Server::get(\OCP\IAppConfig::class); if (!$service instanceof AppConfigOverwrite) { - \OC::$server->registerService(\OCP\IAppConfig::class, function () { + \OC::$server->registerService(\OCP\IAppConfig::class, function ():AppConfigOverwrite { return new AppConfigOverwrite( \OCP\Server::get(\OCP\IDBConnection::class), \OCP\Server::get(\Psr\Log\LoggerInterface::class), @@ -39,10 +39,10 @@ public function mockAppConfig($config) { return $service; } - public function mockConfig($config) { - $service = \OC::$server->get(\OCP\IConfig::class); + public function mockConfig($config):void { + $service = \OCP\Server::get(\OCP\IConfig::class); if (!$service instanceof AllConfigOverwrite) { - \OC::$server->registerService(\OCP\IConfig::class, function () { + \OC::$server->registerService(\OCP\IConfig::class, function ():AllConfigOverwrite { $configOverwrite = new ConfigOverwrite(\OC::$configDir); $systemConfig = new SystemConfig($configOverwrite); return new AllConfigOverwrite($systemConfig); @@ -137,12 +137,8 @@ private function cleanDatabase(): void { /** * Create user - * - * @param string $username - * @param string $password - * @return \OC\User\User */ - public function createAccount($username, $password, $groupName = 'testGroup') { + public function createAccount(string $username, string $password, string $groupName = 'testGroup'):\OC\User\User { $this->users[] = $username; $this->mockConfig([ 'core' => [