Skip to content

Commit 933c54e

Browse files
committed
Improve some console commands coverage
1 parent f3ff059 commit 933c54e

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

module/CLI/test/Command/ShortUrl/CreateShortUrlCommandTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ public function properShortCodeIsCreatedIfLongUrlIsCorrect(): void
6464
self::assertStringNotContainsString('but the real-time updates cannot', $output);
6565
}
6666

67+
#[Test]
68+
public function longUrlIsAskedIfNotProvided(): void
69+
{
70+
$shortUrl = ShortUrl::createFake();
71+
$this->urlShortener->expects($this->once())->method('shorten')->withAnyParameters()->willReturn(
72+
UrlShorteningResult::withoutErrorOnEventDispatching($shortUrl),
73+
);
74+
$this->stringifier->expects($this->once())->method('stringify')->with($shortUrl)->willReturn(
75+
'stringified_short_url',
76+
);
77+
78+
$this->commandTester->setInputs([$shortUrl->getLongUrl()]);
79+
$this->commandTester->execute([]);
80+
}
81+
6782
#[Test]
6883
public function providingNonUniqueSlugOutputsError(): void
6984
{

module/CLI/test/Command/ShortUrl/GetShortUrlVisitsCommandTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ public function noDateFlagsTriesToListWithoutDateRange(): void
5050
$this->commandTester->execute(['shortCode' => $shortCode]);
5151
}
5252

53+
#[Test]
54+
public function shortCodeIsAskedIfNotProvided(): void
55+
{
56+
$shortCode = 'abc123';
57+
$this->visitsHelper->expects($this->once())->method('visitsForShortUrl')->with(
58+
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
59+
$this->anything(),
60+
)->willReturn(new Paginator(new ArrayAdapter([])));
61+
62+
$this->commandTester->setInputs([$shortCode]);
63+
$this->commandTester->execute([]);
64+
}
65+
5366
#[Test]
5467
public function providingDateFlagsTheListGetsFiltered(): void
5568
{

module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ public function correctShortCodeResolvesUrl(): void
4545
self::assertEquals('Long URL: ' . $expectedUrl . PHP_EOL, $output);
4646
}
4747

48+
#[Test]
49+
public function shortCodeIsAskedIfNotProvided(): void
50+
{
51+
$shortCode = 'abc123';
52+
$shortUrl = ShortUrl::createFake();
53+
$this->urlResolver->expects($this->once())->method('resolveShortUrl')->with(
54+
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
55+
)->willReturn($shortUrl);
56+
57+
$this->commandTester->setInputs([$shortCode]);
58+
$this->commandTester->execute([]);
59+
}
60+
4861
#[Test]
4962
public function incorrectShortCodeOutputsErrorMessage(): void
5063
{

0 commit comments

Comments
 (0)