From 933c54e884ed977b755ee4fed214ccf7db16ae5c Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 18 Nov 2025 08:41:42 +0100 Subject: [PATCH] Improve some console commands coverage --- .../ShortUrl/CreateShortUrlCommandTest.php | 15 +++++++++++++++ .../ShortUrl/GetShortUrlVisitsCommandTest.php | 13 +++++++++++++ .../Command/ShortUrl/ResolveUrlCommandTest.php | 13 +++++++++++++ 3 files changed, 41 insertions(+) diff --git a/module/CLI/test/Command/ShortUrl/CreateShortUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/CreateShortUrlCommandTest.php index ff5e3ea6..9452aad5 100644 --- a/module/CLI/test/Command/ShortUrl/CreateShortUrlCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/CreateShortUrlCommandTest.php @@ -64,6 +64,21 @@ class CreateShortUrlCommandTest extends TestCase self::assertStringNotContainsString('but the real-time updates cannot', $output); } + #[Test] + public function longUrlIsAskedIfNotProvided(): void + { + $shortUrl = ShortUrl::createFake(); + $this->urlShortener->expects($this->once())->method('shorten')->withAnyParameters()->willReturn( + UrlShorteningResult::withoutErrorOnEventDispatching($shortUrl), + ); + $this->stringifier->expects($this->once())->method('stringify')->with($shortUrl)->willReturn( + 'stringified_short_url', + ); + + $this->commandTester->setInputs([$shortUrl->getLongUrl()]); + $this->commandTester->execute([]); + } + #[Test] public function providingNonUniqueSlugOutputsError(): void { diff --git a/module/CLI/test/Command/ShortUrl/GetShortUrlVisitsCommandTest.php b/module/CLI/test/Command/ShortUrl/GetShortUrlVisitsCommandTest.php index 709974ec..e306b0bc 100644 --- a/module/CLI/test/Command/ShortUrl/GetShortUrlVisitsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/GetShortUrlVisitsCommandTest.php @@ -50,6 +50,19 @@ class GetShortUrlVisitsCommandTest extends TestCase $this->commandTester->execute(['shortCode' => $shortCode]); } + #[Test] + public function shortCodeIsAskedIfNotProvided(): void + { + $shortCode = 'abc123'; + $this->visitsHelper->expects($this->once())->method('visitsForShortUrl')->with( + ShortUrlIdentifier::fromShortCodeAndDomain($shortCode), + $this->anything(), + )->willReturn(new Paginator(new ArrayAdapter([]))); + + $this->commandTester->setInputs([$shortCode]); + $this->commandTester->execute([]); + } + #[Test] public function providingDateFlagsTheListGetsFiltered(): void { diff --git a/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php index 9c9bbb93..742ae05c 100644 --- a/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php @@ -45,6 +45,19 @@ class ResolveUrlCommandTest extends TestCase self::assertEquals('Long URL: ' . $expectedUrl . PHP_EOL, $output); } + #[Test] + public function shortCodeIsAskedIfNotProvided(): void + { + $shortCode = 'abc123'; + $shortUrl = ShortUrl::createFake(); + $this->urlResolver->expects($this->once())->method('resolveShortUrl')->with( + ShortUrlIdentifier::fromShortCodeAndDomain($shortCode), + )->willReturn($shortUrl); + + $this->commandTester->setInputs([$shortCode]); + $this->commandTester->execute([]); + } + #[Test] public function incorrectShortCodeOutputsErrorMessage(): void {