-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathJavaHelperTest.php
More file actions
76 lines (61 loc) · 2.02 KB
/
JavaHelperTest.php
File metadata and controls
76 lines (61 loc) · 2.02 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
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Libresign\Tests\Unit\Helper;
use OCA\Libresign\AppInfo\Application;
use OCA\Libresign\Helper\JavaHelper;
use OCP\IAppConfig;
use OCP\IL10N;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
class JavaHelperTest extends \OCA\Libresign\Tests\Unit\TestCase {
private IAppConfig $appConfig;
private IL10N|MockObject $l10n;
private LoggerInterface|MockObject $logger;
public function setUp(): void {
parent::setUp();
$this->appConfig = $this->getMockAppConfigWithReset();
$this->l10n = $this->createMock(IL10N::class);
$this->logger = $this->createMock(LoggerInterface::class);
}
private function getInstance(array $methods = []): MockObject|JavaHelper {
if (empty($methods)) {
return new JavaHelper(
$this->appConfig,
$this->l10n,
$this->logger
);
}
return $this->getMockBuilder(JavaHelper::class)
->setConstructorArgs([
$this->appConfig,
$this->l10n,
$this->logger,
])
->onlyMethods($methods)
->getMock();
}
public function testInitSkipsWhenUtf8AlreadySet(): void {
$this->logger->expects($this->never())->method('warning');
$helper = $this->getInstance(['isNonUTF8Locale']);
$helper->method('isNonUTF8Locale')->willReturn(false);
$helper->init();
}
public function testInitSetsUtf8LocaleIfMissing(): void {
$helper = $this->getInstance(['isNonUTF8Locale']);
$helper->method('isNonUTF8Locale')->willReturn(true);
$this->logger->expects($this->once())->method('warning');
$helper->init();
}
public function testGetJavaPathTriggersInit(): void {
$this->appConfig->setValueString(Application::APP_ID, 'java_path', '/usr/bin/java');
$this->logger->expects($this->never())->method('warning');
$helper = $this->getInstance(['isNonUTF8Locale']);
$helper->method('isNonUTF8Locale')->willReturn(false);
$path = $helper->getJavaPath();
$this->assertSame('/usr/bin/java', $path);
}
}