Skip to content

Commit

Permalink
fix: unit tests and linter
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos committed Jan 12, 2025
1 parent 09724b7 commit a6d1ce3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion tests/Api/Controller/FileControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Handler/FooterHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions tests/Unit/Handler/Pkcs12HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Service/Install/SignSetupServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 6 additions & 10 deletions tests/Unit/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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);
Expand Down Expand Up @@ -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' => [
Expand Down

0 comments on commit a6d1ce3

Please sign in to comment.