diff --git a/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php b/module/CLI/test/Command/ShortUrl/GetShortUrlVisitsCommandTest.php similarity index 77% rename from module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php rename to module/CLI/test/Command/ShortUrl/GetShortUrlVisitsCommandTest.php index 93770d55..d5709da6 100644 --- a/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/GetShortUrlVisitsCommandTest.php @@ -23,9 +23,10 @@ use Shlinkio\Shlink\IpGeolocation\Model\Location; use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait; use Symfony\Component\Console\Tester\CommandTester; +use function Shlinkio\Shlink\Common\buildDateRange; use function sprintf; -class GetVisitsCommandTest extends TestCase +class GetShortUrlVisitsCommandTest extends TestCase { use CliTestUtilsTrait; @@ -61,7 +62,7 @@ class GetVisitsCommandTest extends TestCase $endDate = '2016-02-01'; $this->visitsHelper->visitsForShortUrl( ShortUrlIdentifier::fromShortCodeAndDomain($shortCode), - new VisitsParams(DateRange::withStartAndEndDate(Chronos::parse($startDate), Chronos::parse($endDate))), + new VisitsParams(buildDateRange(Chronos::parse($startDate), Chronos::parse($endDate))), ) ->willReturn(new Paginator(new ArrayAdapter([]))) ->shouldBeCalledOnce(); @@ -99,23 +100,32 @@ class GetVisitsCommandTest extends TestCase /** @test */ public function outputIsProperlyGenerated(): void { + $visit = Visit::forValidShortUrl(ShortUrl::createEmpty(), new Visitor('bar', 'foo', '', ''))->locate( + VisitLocation::fromGeolocation(new Location('', 'Spain', '', 'Madrid', 0, 0, '')), + ); $shortCode = 'abc123'; $this->visitsHelper->visitsForShortUrl( ShortUrlIdentifier::fromShortCodeAndDomain($shortCode), Argument::any(), )->willReturn( - new Paginator(new ArrayAdapter([ - Visit::forValidShortUrl(ShortUrl::createEmpty(), new Visitor('bar', 'foo', '', ''))->locate( - VisitLocation::fromGeolocation(new Location('', 'Spain', '', 'Madrid', 0, 0, '')), - ), - ])), + new Paginator(new ArrayAdapter([$visit])), )->shouldBeCalledOnce(); $this->commandTester->execute(['shortCode' => $shortCode]); $output = $this->commandTester->getDisplay(); - self::assertStringContainsString('foo', $output); - self::assertStringContainsString('Spain', $output); - self::assertStringContainsString('Madrid', $output); - self::assertStringContainsString('bar', $output); + + echo $output; + + self::assertEquals( + <<getDate()->toAtomString()} | bar | Spain | Madrid | + +---------+---------------------------+------------+---------+--------+ + + OUTPUT, + $output, + ); } }