Skip to content

Commit 9dd586e

Browse files
committed
Improve IssueCommand coverage: key types and expiry colour branches
- Accept KeyType in makeIssueCert helper - Add tests for EC P-384, RSA 2048, RSA 4096 labels (covers resolveKeyType and keyTypeLabel arms not previously exercised) - Add tests for <= 7 day and <= 30 day expiry to cover daysColor match branches
1 parent 20dc2fc commit 9dd586e

1 file changed

Lines changed: 48 additions & 2 deletions

File tree

tests/Unit/Console/Command/IssueCommandTest.php

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function runIssue(array $input): array
108108

109109
// ── Happy path / exception paths (via stub) ───────────────────────────────────
110110

111-
function makeIssueCert(int $daysUntilExpiry = 90, bool $wasIssued = true): array
111+
function makeIssueCert(int $daysUntilExpiry = 90, bool $wasIssued = true, KeyType $keyType = KeyType::EC_P256): array
112112
{
113113
$cert = new StoredCertificate(
114114
certificate: 'fake-pem',
@@ -118,7 +118,7 @@ function makeIssueCert(int $daysUntilExpiry = 90, bool $wasIssued = true): array
118118
issuedAt: new DateTimeImmutable('-1 day'),
119119
expiresAt: (new DateTimeImmutable())->modify("+{$daysUntilExpiry} days"),
120120
domains: ['example.com'],
121-
keyType: KeyType::EC_P256,
121+
keyType: $keyType,
122122
);
123123

124124
return [$cert, $wasIssued];
@@ -225,3 +225,49 @@ function runStub(mixed $result, array $input = []): array
225225

226226
expect($code)->toBe(Command::SUCCESS);
227227
});
228+
229+
// ── key type labels in renderSuccess ─────────────────────────────────────────
230+
231+
it('shows EC P-384 key type label in success output', function () {
232+
[$code, $output] = runStub(
233+
makeIssueCert(keyType: KeyType::EC_P384),
234+
['--key-type' => 'ec384'],
235+
);
236+
237+
expect($code)->toBe(Command::SUCCESS);
238+
expect($output)->toContain('EC P-384');
239+
});
240+
241+
it('shows RSA 2048 key type label in success output', function () {
242+
[$code, $output] = runStub(
243+
makeIssueCert(keyType: KeyType::RSA_2048),
244+
['--key-type' => 'rsa2048'],
245+
);
246+
247+
expect($code)->toBe(Command::SUCCESS);
248+
expect($output)->toContain('RSA 2048');
249+
});
250+
251+
it('shows RSA 4096 key type label in success output', function () {
252+
[$code, $output] = runStub(
253+
makeIssueCert(keyType: KeyType::RSA_4096),
254+
['--key-type' => 'rsa4096'],
255+
);
256+
257+
expect($code)->toBe(Command::SUCCESS);
258+
expect($output)->toContain('RSA 4096');
259+
});
260+
261+
// ── expiry colour branches in renderSuccess ───────────────────────────────────
262+
263+
it('uses warning colour when certificate expires within 7 days', function () {
264+
[$code] = runStub(makeIssueCert(daysUntilExpiry: 5));
265+
266+
expect($code)->toBe(Command::SUCCESS);
267+
});
268+
269+
it('uses caution colour when certificate expires within 30 days', function () {
270+
[$code] = runStub(makeIssueCert(daysUntilExpiry: 20));
271+
272+
expect($code)->toBe(Command::SUCCESS);
273+
});

0 commit comments

Comments
 (0)