mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Improved GetShortUrlVisitsCommand test
This commit is contained in:
parent
353ac0fc0c
commit
fba7b36245
@ -23,9 +23,10 @@ use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
|||||||
use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait;
|
use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
|
|
||||||
|
use function Shlinkio\Shlink\Common\buildDateRange;
|
||||||
use function sprintf;
|
use function sprintf;
|
||||||
|
|
||||||
class GetVisitsCommandTest extends TestCase
|
class GetShortUrlVisitsCommandTest extends TestCase
|
||||||
{
|
{
|
||||||
use CliTestUtilsTrait;
|
use CliTestUtilsTrait;
|
||||||
|
|
||||||
@ -61,7 +62,7 @@ class GetVisitsCommandTest extends TestCase
|
|||||||
$endDate = '2016-02-01';
|
$endDate = '2016-02-01';
|
||||||
$this->visitsHelper->visitsForShortUrl(
|
$this->visitsHelper->visitsForShortUrl(
|
||||||
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
|
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([])))
|
->willReturn(new Paginator(new ArrayAdapter([])))
|
||||||
->shouldBeCalledOnce();
|
->shouldBeCalledOnce();
|
||||||
@ -99,23 +100,32 @@ class GetVisitsCommandTest extends TestCase
|
|||||||
/** @test */
|
/** @test */
|
||||||
public function outputIsProperlyGenerated(): void
|
public function outputIsProperlyGenerated(): void
|
||||||
{
|
{
|
||||||
|
$visit = Visit::forValidShortUrl(ShortUrl::createEmpty(), new Visitor('bar', 'foo', '', ''))->locate(
|
||||||
|
VisitLocation::fromGeolocation(new Location('', 'Spain', '', 'Madrid', 0, 0, '')),
|
||||||
|
);
|
||||||
$shortCode = 'abc123';
|
$shortCode = 'abc123';
|
||||||
$this->visitsHelper->visitsForShortUrl(
|
$this->visitsHelper->visitsForShortUrl(
|
||||||
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
|
ShortUrlIdentifier::fromShortCodeAndDomain($shortCode),
|
||||||
Argument::any(),
|
Argument::any(),
|
||||||
)->willReturn(
|
)->willReturn(
|
||||||
new Paginator(new ArrayAdapter([
|
new Paginator(new ArrayAdapter([$visit])),
|
||||||
Visit::forValidShortUrl(ShortUrl::createEmpty(), new Visitor('bar', 'foo', '', ''))->locate(
|
|
||||||
VisitLocation::fromGeolocation(new Location('', 'Spain', '', 'Madrid', 0, 0, '')),
|
|
||||||
),
|
|
||||||
])),
|
|
||||||
)->shouldBeCalledOnce();
|
)->shouldBeCalledOnce();
|
||||||
|
|
||||||
$this->commandTester->execute(['shortCode' => $shortCode]);
|
$this->commandTester->execute(['shortCode' => $shortCode]);
|
||||||
$output = $this->commandTester->getDisplay();
|
$output = $this->commandTester->getDisplay();
|
||||||
self::assertStringContainsString('foo', $output);
|
|
||||||
self::assertStringContainsString('Spain', $output);
|
echo $output;
|
||||||
self::assertStringContainsString('Madrid', $output);
|
|
||||||
self::assertStringContainsString('bar', $output);
|
self::assertEquals(
|
||||||
|
<<<OUTPUT
|
||||||
|
+---------+---------------------------+------------+---------+--------+
|
||||||
|
| Referer | Date | User agent | Country | City |
|
||||||
|
+---------+---------------------------+------------+---------+--------+
|
||||||
|
| foo | {$visit->getDate()->toAtomString()} | bar | Spain | Madrid |
|
||||||
|
+---------+---------------------------+------------+---------+--------+
|
||||||
|
|
||||||
|
OUTPUT,
|
||||||
|
$output,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user