Improve some console commands coverage

This commit is contained in:
Alejandro Celaya 2025-11-18 08:41:42 +01:00
parent f3ff059d48
commit 933c54e884
3 changed files with 41 additions and 0 deletions

View File

@ -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
{

View File

@ -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
{

View File

@ -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
{