mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-10 17:23:12 +08:00
Allow filtering orphan visits by type from the CLI
This commit is contained in:
@@ -6,12 +6,15 @@ namespace ShlinkioTest\Shlink\CLI\Command\Visit;
|
||||
|
||||
use Pagerfanta\Adapter\ArrayAdapter;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\TestWith;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\CLI\Command\Visit\GetOrphanVisitsCommand;
|
||||
use Shlinkio\Shlink\Common\Paginator\Paginator;
|
||||
use Shlinkio\Shlink\Core\Visit\Entity\Visit;
|
||||
use Shlinkio\Shlink\Core\Visit\Entity\VisitLocation;
|
||||
use Shlinkio\Shlink\Core\Visit\Model\OrphanVisitsParams;
|
||||
use Shlinkio\Shlink\Core\Visit\Model\OrphanVisitType;
|
||||
use Shlinkio\Shlink\Core\Visit\Model\Visitor;
|
||||
use Shlinkio\Shlink\Core\Visit\VisitsStatsHelperInterface;
|
||||
use Shlinkio\Shlink\IpGeolocation\Model\Location;
|
||||
@@ -30,16 +33,20 @@ class GetOrphanVisitsCommandTest extends TestCase
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function outputIsProperlyGenerated(): void
|
||||
#[TestWith([[], false])]
|
||||
#[TestWith([['--type' => OrphanVisitType::BASE_URL->value], true])]
|
||||
public function outputIsProperlyGenerated(array $args, bool $includesType): void
|
||||
{
|
||||
$visit = Visit::forBasePath(new Visitor('bar', 'foo', '', ''))->locate(
|
||||
VisitLocation::fromGeolocation(new Location('', 'Spain', '', 'Madrid', 0, 0, '')),
|
||||
);
|
||||
$this->visitsHelper->expects($this->once())->method('orphanVisits')->withAnyParameters()->willReturn(
|
||||
new Paginator(new ArrayAdapter([$visit])),
|
||||
);
|
||||
$this->visitsHelper->expects($this->once())->method('orphanVisits')->with($this->callback(
|
||||
fn (OrphanVisitsParams $param) => (
|
||||
($includesType && $param->type !== null) || (!$includesType && $param->type === null)
|
||||
),
|
||||
))->willReturn(new Paginator(new ArrayAdapter([$visit])));
|
||||
|
||||
$this->commandTester->execute([]);
|
||||
$this->commandTester->execute($args);
|
||||
$output = $this->commandTester->getDisplay();
|
||||
|
||||
self::assertEquals(
|
||||
|
||||
Reference in New Issue
Block a user