2022-05-24 18:59:06 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\CLI\Command\Visit;
|
|
|
|
|
|
|
|
use Pagerfanta\Adapter\ArrayAdapter;
|
2022-10-22 15:06:54 +03:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2022-05-24 18:59:06 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Shlinkio\Shlink\CLI\Command\Visit\GetOrphanVisitsCommand;
|
|
|
|
use Shlinkio\Shlink\Common\Paginator\Paginator;
|
2022-09-23 20:03:32 +03:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Entity\Visit;
|
|
|
|
use Shlinkio\Shlink\Core\Visit\Entity\VisitLocation;
|
2022-09-23 19:05:17 +03:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Model\Visitor;
|
2022-05-24 18:59:06 +03:00
|
|
|
use Shlinkio\Shlink\Core\Visit\VisitsStatsHelperInterface;
|
|
|
|
use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
|
|
|
use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait;
|
|
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
|
|
|
|
|
|
|
class GetOrphanVisitsCommandTest extends TestCase
|
|
|
|
{
|
|
|
|
use CliTestUtilsTrait;
|
|
|
|
|
|
|
|
private CommandTester $commandTester;
|
2022-10-22 15:06:54 +03:00
|
|
|
private MockObject $visitsHelper;
|
2022-05-24 18:59:06 +03:00
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
2022-10-22 15:06:54 +03:00
|
|
|
$this->visitsHelper = $this->createMock(VisitsStatsHelperInterface::class);
|
|
|
|
$this->commandTester = $this->testerForCommand(new GetOrphanVisitsCommand($this->visitsHelper));
|
2022-05-24 18:59:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
public function outputIsProperlyGenerated(): void
|
|
|
|
{
|
|
|
|
$visit = Visit::forBasePath(new Visitor('bar', 'foo', '', ''))->locate(
|
|
|
|
VisitLocation::fromGeolocation(new Location('', 'Spain', '', 'Madrid', 0, 0, '')),
|
|
|
|
);
|
2022-10-22 15:06:54 +03:00
|
|
|
$this->visitsHelper->expects($this->once())->method('orphanVisits')->withAnyParameters()->willReturn(
|
2022-05-24 18:59:06 +03:00
|
|
|
new Paginator(new ArrayAdapter([$visit])),
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->commandTester->execute([]);
|
|
|
|
$output = $this->commandTester->getDisplay();
|
|
|
|
|
|
|
|
self::assertEquals(
|
|
|
|
<<<OUTPUT
|
|
|
|
+---------+---------------------------+------------+---------+--------+----------+
|
|
|
|
| Referer | Date | User agent | Country | City | Type |
|
|
|
|
+---------+---------------------------+------------+---------+--------+----------+
|
|
|
|
| foo | {$visit->getDate()->toAtomString()} | bar | Spain | Madrid | base_url |
|
|
|
|
+---------+---------------------------+------------+---------+--------+----------+
|
|
|
|
|
|
|
|
OUTPUT,
|
|
|
|
$output,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|