-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathConfigureCheckServiceTest.php
More file actions
104 lines (89 loc) · 3.48 KB
/
ConfigureCheckServiceTest.php
File metadata and controls
104 lines (89 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
/**
* Mock extension_loaded in the ConfigureCheckService namespace to control its behavior in tests
*/
namespace OCA\Libresign\Service\Install;
function extension_loaded(string $name): bool {
return \OCA\Libresign\Tests\Unit\Service\Install\ConfigureCheckServiceTest::$mockExtensionLoaded[$name] ?? \extension_loaded($name);
}
namespace OCA\Libresign\Tests\Unit\Service\Install;
use OC\AppConfig;
use OC\SystemConfig;
use OCA\Libresign\Handler\CertificateEngine\CertificateEngineFactory;
use OCA\Libresign\Handler\SignEngine\JSignPdfHandler;
use OCA\Libresign\Helper\ConfigureCheckHelper;
use OCA\Libresign\Helper\JavaHelper;
use OCA\Libresign\Service\Install\ConfigureCheckService;
use OCA\Libresign\Service\Install\SignSetupService;
use OCP\App\IAppManager;
use OCP\IAppConfig;
use OCP\IURLGenerator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
final class ConfigureCheckServiceTest extends \OCA\Libresign\Tests\Unit\TestCase {
public static array $mockExtensionLoaded = [];
private IAppConfig $appConfig;
private SystemConfig&MockObject $systemConfig;
private AppConfig&MockObject $ocAppConfig;
private IAppManager&MockObject $appManager;
private IURLGenerator&MockObject $urlGenerator;
private JSignPdfHandler&MockObject $jSignPdfHandler;
private CertificateEngineFactory&MockObject $certificateEngineFactory;
private SignSetupService&MockObject $signSetupService;
private LoggerInterface&MockObject $logger;
private JavaHelper&MockObject $javaHelper;
public function setUp(): void {
self::$mockExtensionLoaded = [];
$this->appConfig = $this->getMockAppConfigWithReset();
$this->systemConfig = $this->createMock(SystemConfig::class);
$this->ocAppConfig = $this->createMock(AppConfig::class);
$this->appManager = $this->createMock(IAppManager::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->jSignPdfHandler = $this->createMock(JSignPdfHandler::class);
$this->certificateEngineFactory = $this->createMock(CertificateEngineFactory::class);
$this->signSetupService = $this->createMock(SignSetupService::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->javaHelper = $this->createMock(JavaHelper::class);
}
public function tearDown(): void {
self::$mockExtensionLoaded = [];
}
private function getInstance(): ConfigureCheckService {
return new ConfigureCheckService(
$this->appConfig,
$this->systemConfig,
$this->ocAppConfig,
$this->appManager,
$this->urlGenerator,
$this->jSignPdfHandler,
$this->certificateEngineFactory,
$this->signSetupService,
$this->logger,
$this->javaHelper,
);
}
public static function providerCheckExtension(): array {
return [
'extension not loaded' => ['imagick', false, 1],
'extension loaded' => ['imagick', true, 0],
];
}
#[DataProvider('providerCheckExtension')]
public function testCheckExtension(string $extension, bool $extensionLoaded, int $expectedCount): void {
self::$mockExtensionLoaded[$extension] = $extensionLoaded;
$service = $this->getInstance();
$result = $service->checkImagick();
$this->assertIsArray($result);
$this->assertCount($expectedCount, $result);
if ($expectedCount > 0) {
$this->assertInstanceOf(ConfigureCheckHelper::class, $result[0]);
$this->assertEquals($extension, $result[0]->getResource());
}
}
}