-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathSerialNumberServiceTest.php
More file actions
57 lines (47 loc) · 1.33 KB
/
SerialNumberServiceTest.php
File metadata and controls
57 lines (47 loc) · 1.33 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
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Libresign\Tests\Unit\Service;
use DateTime;
use OCA\Libresign\Db\CrlMapper;
use OCA\Libresign\Service\SerialNumberService;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
class SerialNumberServiceTest extends TestCase {
private CrlMapper&MockObject $crlMapper;
private SerialNumberService $service;
protected function setUp(): void {
parent::setUp();
$this->crlMapper = $this->createMock(CrlMapper::class);
$this->service = new SerialNumberService($this->crlMapper);
}
public function testGenerateUniqueSerialPersistsCrlMetadata(): void {
$expiresAt = new DateTime('2030-01-01 00:00:00');
$this->crlMapper->expects($this->once())
->method('createCertificate')
->with(
$this->callback(static fn (mixed $value): bool => is_string($value) && $value !== ''),
'test-owner',
'openssl',
'inst1234567',
4,
$this->isInstanceOf(DateTime::class),
$expiresAt,
null,
null,
'leaf'
);
$serial = $this->service->generateUniqueSerial(
'test-owner',
'inst1234567',
4,
$expiresAt,
'openssl',
);
$this->assertNotSame('', $serial);
$this->assertSame(1, preg_match('/^[0-9]+$/', $serial));
}
}