Skip to content

Commit c9b7afa

Browse files
committed
test: add session service data provider coverage
Signed-off-by: Vitor Mattos <[email protected]>
1 parent 8778257 commit c9b7afa

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OCA\Libresign\Tests\Unit\Service;
6+
7+
/**
8+
* SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
9+
* SPDX-License-Identifier: AGPL-3.0-or-later
10+
*/
11+
12+
use OCA\Libresign\Service\SessionService;
13+
use OCP\IAppConfig;
14+
use OCP\ISession;
15+
use PHPUnit\Framework\Attributes\DataProvider;
16+
use PHPUnit\Framework\MockObject\MockObject;
17+
18+
final class SessionServiceTest extends \OCA\Libresign\Tests\Unit\TestCase {
19+
private ISession&MockObject $session;
20+
private IAppConfig&MockObject $appConfig;
21+
22+
public function setUp(): void {
23+
$this->session = $this->createMock(ISession::class);
24+
$this->appConfig = $this->createMock(IAppConfig::class);
25+
}
26+
27+
private function getService(): SessionService {
28+
return new SessionService(
29+
$this->session,
30+
$this->appConfig,
31+
);
32+
}
33+
34+
#[DataProvider('providerGetSessionId')]
35+
public function testGetSessionIdUsesUuidWhenAvailable(mixed $uuidInSession, string $sessionId, string $expected): void {
36+
$this->session->method('get')
37+
->with('libresign-uuid')
38+
->willReturn($uuidInSession);
39+
$this->session->method('getId')
40+
->willReturn($sessionId);
41+
42+
$this->assertSame($expected, $this->getService()->getSessionId());
43+
}
44+
45+
public static function providerGetSessionId(): array {
46+
return [
47+
'uuid string present' => ['54afbd0a-a065-4eaf-b611-48ec381b116a', 'session-123', '54afbd0a-a065-4eaf-b611-48ec381b116a'],
48+
'uuid empty string' => ['', 'session-123', 'session-123'],
49+
'uuid null' => [null, 'session-123', 'session-123'],
50+
'uuid non-string' => [123, 'session-123', 'session-123'],
51+
];
52+
}
53+
}

0 commit comments

Comments
 (0)