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 8bb7fb5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 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
7 changes: 3 additions & 4 deletions 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 Expand Up @@ -200,9 +201,7 @@ public function testVerify(): void {
$this->assertJsonStringEqualsJsonString($expected, $actual);
}

/**
* @dataProvider dataGetInstallPath
*/
#[DataProvider('dataGetInstallPath')]
public function testGetInstallPath(string $architecture, string $resource, string $distro, string $expected): void {
$this->appConfig->setValueString(Application::APP_ID, 'java_path', 'vfs://home/data/appdata_1/libresign/x86_64/linux/java/jdk-21.0.2+13-jre/bin/java');
$this->appConfig->setValueString(Application::APP_ID, 'jsignpdf_jar_path', 'vfs://home/data/appdata_1/libresign/x86_64/jsignpdf/jsignpdf-2.2.2/JSignPdf.jar');
Expand Down
22 changes: 9 additions & 13 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 @@ -71,7 +71,7 @@ public function haveDependents(): bool {
if (!$docblock) {
return false;
}
if (preg_match('#@depends ' . $this->getName(false) . '\n#s', $docblock)) {
if (preg_match('#@depends ' . $this->name() . '\n#s', $docblock)) {
return true;
}
}
Expand All @@ -80,7 +80,7 @@ public function haveDependents(): bool {

public function iDependOnOthers(): bool {
$reflector = new \ReflectionClass(\get_class($this));
$docblock = $reflector->getMethod($this->getName(false))->getDocComment();
$docblock = $reflector->getMethod($this->name())->getDocComment();
if (!$docblock) {
return false;
}
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 Expand Up @@ -172,7 +168,7 @@ public function markUserExists($username): void {
$this->users[] = $username;
}

public function deleteUsers() {
public function deleteUsers():void {
foreach ($this->users as $username) {
$this->deleteUserIfExists($username);
}
Expand Down

0 comments on commit 8bb7fb5

Please sign in to comment.