Skip to content

Commit 3dfa16e

Browse files
committed
Improve some console commands coverage
1 parent f3ff059 commit 3dfa16e

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
1717
use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifierInterface;
1818
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation;
19+
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
1920
use Shlinkio\Shlink\Core\ShortUrl\Model\UrlShorteningResult;
2021
use Shlinkio\Shlink\Core\ShortUrl\UrlShortenerInterface;
2122
use ShlinkioTest\Shlink\CLI\Util\CliTestUtils;
@@ -64,6 +65,21 @@ public function properShortCodeIsCreatedIfLongUrlIsCorrect(): void
6465
self::assertStringNotContainsString('but the real-time updates cannot', $output);
6566
}
6667

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

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)