2020-05-01 11:57:46 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Core\Visit;
|
|
|
|
|
|
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
2021-02-08 19:46:51 +01:00
|
|
|
use Laminas\Stdlib\ArrayUtils;
|
2023-02-09 09:32:38 +01:00
|
|
|
use PHPUnit\Framework\Assert;
|
2023-02-09 20:42:18 +01:00
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
2023-06-18 10:41:24 +02:00
|
|
|
use PHPUnit\Framework\Attributes\DataProviderExternal;
|
2023-02-09 20:42:18 +01:00
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2022-10-23 21:05:13 +02:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2020-05-01 11:57:46 +02:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2025-10-31 08:53:31 +01:00
|
|
|
use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions;
|
2022-09-23 19:03:32 +02:00
|
|
|
use Shlinkio\Shlink\Core\Domain\Entity\Domain;
|
2022-04-23 11:02:51 +02:00
|
|
|
use Shlinkio\Shlink\Core\Domain\Repository\DomainRepository;
|
|
|
|
|
use Shlinkio\Shlink\Core\Exception\DomainNotFoundException;
|
2021-02-08 19:46:51 +01:00
|
|
|
use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException;
|
|
|
|
|
use Shlinkio\Shlink\Core\Exception\TagNotFoundException;
|
2022-09-23 19:03:32 +02:00
|
|
|
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
2022-09-23 18:05:17 +02:00
|
|
|
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
|
2024-02-17 10:21:36 +01:00
|
|
|
use Shlinkio\Shlink\Core\ShortUrl\Repository\ShortUrlRepository;
|
2022-09-23 19:03:32 +02:00
|
|
|
use Shlinkio\Shlink\Core\Tag\Entity\Tag;
|
2022-09-23 18:24:14 +02:00
|
|
|
use Shlinkio\Shlink\Core\Tag\Repository\TagRepository;
|
2024-04-01 10:22:51 +02:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Entity\OrphanVisitsCount;
|
2024-03-31 10:33:31 +02:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Entity\ShortUrlVisitsCount;
|
2022-09-23 19:03:32 +02:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Entity\Visit;
|
2024-02-10 17:51:42 +01:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Model\OrphanVisitsParams;
|
2022-09-23 18:05:17 +02:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Model\Visitor;
|
|
|
|
|
use Shlinkio\Shlink\Core\Visit\Model\VisitsParams;
|
2020-05-01 11:57:46 +02:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Model\VisitsStats;
|
2025-10-28 10:55:06 +01:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Model\WithDomainVisitsParams;
|
2024-02-10 13:57:16 +01:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Persistence\OrphanVisitsCountFiltering;
|
|
|
|
|
use Shlinkio\Shlink\Core\Visit\Persistence\OrphanVisitsListFiltering;
|
2021-05-22 20:16:32 +02:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Persistence\VisitsCountFiltering;
|
2025-10-28 10:55:06 +01:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Persistence\WithDomainVisitsCountFiltering;
|
|
|
|
|
use Shlinkio\Shlink\Core\Visit\Persistence\WithDomainVisitsListFiltering;
|
2024-04-01 10:22:51 +02:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Repository\OrphanVisitsCountRepository;
|
2024-03-31 10:33:31 +02:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Repository\ShortUrlVisitsCountRepository;
|
2022-09-23 18:24:14 +02:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Repository\VisitRepository;
|
2020-05-01 11:57:46 +02:00
|
|
|
use Shlinkio\Shlink\Core\Visit\VisitsStatsHelper;
|
2021-02-08 19:46:51 +01:00
|
|
|
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
2023-06-18 10:41:24 +02:00
|
|
|
use ShlinkioTest\Shlink\Core\Util\ApiKeyDataProviders;
|
2020-05-01 11:57:46 +02:00
|
|
|
|
2023-11-29 12:34:13 +01:00
|
|
|
use function array_map;
|
2021-02-09 22:40:40 +01:00
|
|
|
use function count;
|
2020-05-01 11:57:46 +02:00
|
|
|
use function range;
|
|
|
|
|
|
|
|
|
|
class VisitsStatsHelperTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
private VisitsStatsHelper $helper;
|
2026-05-22 08:42:47 +02:00
|
|
|
private MockObject&EntityManagerInterface $em;
|
2020-05-01 11:57:46 +02:00
|
|
|
|
2022-09-11 12:02:49 +02:00
|
|
|
protected function setUp(): void
|
2020-05-01 11:57:46 +02:00
|
|
|
{
|
2022-10-23 21:05:13 +02:00
|
|
|
$this->em = $this->createMock(EntityManagerInterface::class);
|
2025-10-31 08:53:31 +01:00
|
|
|
$this->helper = new VisitsStatsHelper($this->em, new UrlShortenerOptions());
|
2020-05-01 11:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
2023-02-09 20:42:18 +01:00
|
|
|
#[Test, DataProvider('provideCounts')]
|
2024-10-28 22:27:30 +01:00
|
|
|
public function returnsExpectedVisitsStats(int $expectedCount, ApiKey|null $apiKey): void
|
2020-05-01 11:57:46 +02:00
|
|
|
{
|
2023-02-09 09:32:38 +01:00
|
|
|
$callCount = 0;
|
2024-03-31 10:33:31 +02:00
|
|
|
$visitsCountRepo = $this->createMock(ShortUrlVisitsCountRepository::class);
|
2026-05-22 18:09:59 +02:00
|
|
|
$visitsCountRepo
|
|
|
|
|
->expects($this->exactly(2))
|
2026-05-22 08:42:47 +02:00
|
|
|
->method('countNonOrphanVisits')
|
|
|
|
|
->willReturnCallback(
|
|
|
|
|
static function (VisitsCountFiltering $options) use ($expectedCount, $apiKey, &$callCount) {
|
|
|
|
|
Assert::assertEquals($callCount !== 0, $options->excludeBots);
|
|
|
|
|
Assert::assertEquals($apiKey, $options->apiKey);
|
|
|
|
|
$callCount++;
|
|
|
|
|
|
|
|
|
|
return $expectedCount * 3;
|
|
|
|
|
},
|
|
|
|
|
);
|
2024-03-31 10:33:31 +02:00
|
|
|
|
2024-04-01 10:22:51 +02:00
|
|
|
$orphanVisitsCountRepo = $this->createMock(OrphanVisitsCountRepository::class);
|
2026-05-22 18:09:59 +02:00
|
|
|
$orphanVisitsCountRepo
|
|
|
|
|
->expects($this->exactly(2))
|
2026-05-22 08:42:47 +02:00
|
|
|
->method('countOrphanVisits')
|
|
|
|
|
->with(
|
|
|
|
|
$this->isInstanceOf(VisitsCountFiltering::class),
|
|
|
|
|
)
|
|
|
|
|
->willReturn($expectedCount);
|
|
|
|
|
|
|
|
|
|
$this->em
|
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
|
->method('getRepository')
|
|
|
|
|
->willReturnMap([
|
|
|
|
|
[OrphanVisitsCount::class, $orphanVisitsCountRepo],
|
|
|
|
|
[ShortUrlVisitsCount::class, $visitsCountRepo],
|
|
|
|
|
]);
|
2020-05-01 11:57:46 +02:00
|
|
|
|
2023-05-31 09:11:20 +02:00
|
|
|
$stats = $this->helper->getVisitsStats($apiKey);
|
2020-05-01 11:57:46 +02:00
|
|
|
|
2021-02-08 22:44:58 +01:00
|
|
|
self::assertEquals(new VisitsStats($expectedCount * 3, $expectedCount), $stats);
|
2020-05-01 11:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
2023-02-09 09:32:38 +01:00
|
|
|
public static function provideCounts(): iterable
|
2020-05-01 11:57:46 +02:00
|
|
|
{
|
2023-05-31 09:11:20 +02:00
|
|
|
return [
|
2026-05-16 11:21:43 +02:00
|
|
|
...array_map(static fn (int $value) => [$value, null], range(0, 50, 5)),
|
|
|
|
|
...array_map(static fn (int $value) => [$value, ApiKey::create()], range(0, 18, 3)),
|
2023-05-31 09:11:20 +02:00
|
|
|
];
|
2020-05-01 11:57:46 +02:00
|
|
|
}
|
2021-02-08 19:46:51 +01:00
|
|
|
|
2023-06-18 10:41:24 +02:00
|
|
|
#[Test, DataProviderExternal(ApiKeyDataProviders::class, 'adminApiKeysProvider')]
|
2024-10-28 22:27:30 +01:00
|
|
|
public function infoReturnsVisitsForCertainShortCode(ApiKey|null $apiKey): void
|
2021-02-08 19:46:51 +01:00
|
|
|
{
|
|
|
|
|
$shortCode = '123ABC';
|
2021-05-23 08:41:42 +02:00
|
|
|
$identifier = ShortUrlIdentifier::fromShortCodeAndDomain($shortCode);
|
2021-05-23 12:31:10 +02:00
|
|
|
$spec = $apiKey?->spec();
|
2021-05-23 08:41:42 +02:00
|
|
|
|
2024-02-17 10:21:36 +01:00
|
|
|
$repo = $this->createMock(ShortUrlRepository::class);
|
2022-10-23 21:05:13 +02:00
|
|
|
$repo->expects($this->once())->method('shortCodeIsInUse')->with($identifier, $spec)->willReturn(true);
|
2021-02-08 19:46:51 +01:00
|
|
|
|
2023-11-29 12:34:13 +01:00
|
|
|
$list = array_map(
|
2024-11-11 08:51:55 +01:00
|
|
|
static fn () => Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::empty()),
|
2023-11-29 12:34:13 +01:00
|
|
|
range(0, 1),
|
|
|
|
|
);
|
2025-12-15 14:17:36 +01:00
|
|
|
$repo2 = $this->createStub(VisitRepository::class);
|
2025-02-13 10:35:58 +01:00
|
|
|
$repo2->method('findVisitsByShortCode')->willReturn($list);
|
|
|
|
|
$repo2->method('countVisitsByShortCode')->willReturn(1);
|
2022-10-23 21:05:13 +02:00
|
|
|
|
2026-05-22 08:42:47 +02:00
|
|
|
$this->em
|
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
|
->method('getRepository')
|
|
|
|
|
->willReturnMap([
|
|
|
|
|
[ShortUrl::class, $repo],
|
|
|
|
|
[Visit::class, $repo2],
|
|
|
|
|
]);
|
2021-02-08 19:46:51 +01:00
|
|
|
|
2021-05-23 08:41:42 +02:00
|
|
|
$paginator = $this->helper->visitsForShortUrl($identifier, new VisitsParams(), $apiKey);
|
2021-02-08 19:46:51 +01:00
|
|
|
|
|
|
|
|
self::assertEquals($list, ArrayUtils::iteratorToArray($paginator->getCurrentPageResults()));
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-09 20:42:18 +01:00
|
|
|
#[Test]
|
2021-02-08 19:46:51 +01:00
|
|
|
public function throwsExceptionWhenRequestingVisitsForInvalidShortCode(): void
|
|
|
|
|
{
|
|
|
|
|
$shortCode = '123ABC';
|
2021-05-23 08:41:42 +02:00
|
|
|
$identifier = ShortUrlIdentifier::fromShortCodeAndDomain($shortCode);
|
|
|
|
|
|
2024-02-17 10:21:36 +01:00
|
|
|
$repo = $this->createMock(ShortUrlRepository::class);
|
2022-10-23 21:05:13 +02:00
|
|
|
$repo->expects($this->once())->method('shortCodeIsInUse')->with($identifier, null)->willReturn(false);
|
|
|
|
|
$this->em->expects($this->once())->method('getRepository')->with(ShortUrl::class)->willReturn($repo);
|
2021-02-08 19:46:51 +01:00
|
|
|
|
|
|
|
|
$this->expectException(ShortUrlNotFoundException::class);
|
|
|
|
|
|
2021-05-23 08:41:42 +02:00
|
|
|
$this->helper->visitsForShortUrl($identifier, new VisitsParams());
|
2021-02-08 19:46:51 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-09 20:42:18 +01:00
|
|
|
#[Test]
|
2021-02-08 19:46:51 +01:00
|
|
|
public function throwsExceptionWhenRequestingVisitsForInvalidTag(): void
|
|
|
|
|
{
|
|
|
|
|
$tag = 'foo';
|
2021-03-14 09:59:35 +01:00
|
|
|
$apiKey = ApiKey::create();
|
2022-10-23 21:05:13 +02:00
|
|
|
$repo = $this->createMock(TagRepository::class);
|
|
|
|
|
$repo->expects($this->once())->method('tagExists')->with($tag, $apiKey)->willReturn(false);
|
|
|
|
|
$this->em->expects($this->once())->method('getRepository')->with(Tag::class)->willReturn($repo);
|
2021-02-08 19:46:51 +01:00
|
|
|
|
|
|
|
|
$this->expectException(TagNotFoundException::class);
|
|
|
|
|
|
2025-10-28 10:55:06 +01:00
|
|
|
$this->helper->visitsForTag($tag, new WithDomainVisitsParams(), $apiKey);
|
2021-02-08 19:46:51 +01:00
|
|
|
}
|
|
|
|
|
|
2023-06-18 10:41:24 +02:00
|
|
|
#[Test, DataProviderExternal(ApiKeyDataProviders::class, 'adminApiKeysProvider')]
|
2024-10-28 22:27:30 +01:00
|
|
|
public function visitsForTagAreReturnedAsExpected(ApiKey|null $apiKey): void
|
2021-02-08 19:46:51 +01:00
|
|
|
{
|
|
|
|
|
$tag = 'foo';
|
2022-10-23 21:05:13 +02:00
|
|
|
$repo = $this->createMock(TagRepository::class);
|
|
|
|
|
$repo->expects($this->once())->method('tagExists')->with($tag, $apiKey)->willReturn(true);
|
2021-02-08 19:46:51 +01:00
|
|
|
|
2023-11-29 12:34:13 +01:00
|
|
|
$list = array_map(
|
2024-11-11 08:51:55 +01:00
|
|
|
static fn () => Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::empty()),
|
2023-11-29 12:34:13 +01:00
|
|
|
range(0, 1),
|
|
|
|
|
);
|
2025-12-15 14:17:36 +01:00
|
|
|
$repo2 = $this->createStub(VisitRepository::class);
|
2025-02-13 10:35:58 +01:00
|
|
|
$repo2->method('findVisitsByTag')->willReturn($list);
|
|
|
|
|
$repo2->method('countVisitsByTag')->willReturn(1);
|
2022-10-23 21:05:13 +02:00
|
|
|
|
2026-05-22 08:42:47 +02:00
|
|
|
$this->em
|
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
|
->method('getRepository')
|
|
|
|
|
->willReturnMap([
|
|
|
|
|
[Tag::class, $repo],
|
|
|
|
|
[Visit::class, $repo2],
|
|
|
|
|
]);
|
2021-02-08 19:46:51 +01:00
|
|
|
|
2025-10-28 10:55:06 +01:00
|
|
|
$paginator = $this->helper->visitsForTag($tag, new WithDomainVisitsParams(), $apiKey);
|
2021-02-08 19:46:51 +01:00
|
|
|
|
|
|
|
|
self::assertEquals($list, ArrayUtils::iteratorToArray($paginator->getCurrentPageResults()));
|
|
|
|
|
}
|
2021-02-09 22:40:40 +01:00
|
|
|
|
2023-02-09 20:42:18 +01:00
|
|
|
#[Test]
|
2022-04-23 11:02:51 +02:00
|
|
|
public function throwsExceptionWhenRequestingVisitsForInvalidDomain(): void
|
|
|
|
|
{
|
|
|
|
|
$domain = 'foo.com';
|
|
|
|
|
$apiKey = ApiKey::create();
|
2022-10-23 21:05:13 +02:00
|
|
|
$repo = $this->createMock(DomainRepository::class);
|
|
|
|
|
$repo->expects($this->once())->method('domainExists')->with($domain, $apiKey)->willReturn(false);
|
|
|
|
|
$this->em->expects($this->once())->method('getRepository')->with(Domain::class)->willReturn($repo);
|
2022-04-23 11:02:51 +02:00
|
|
|
|
|
|
|
|
$this->expectException(DomainNotFoundException::class);
|
|
|
|
|
|
|
|
|
|
$this->helper->visitsForDomain($domain, new VisitsParams(), $apiKey);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-18 10:41:24 +02:00
|
|
|
#[Test, DataProviderExternal(ApiKeyDataProviders::class, 'adminApiKeysProvider')]
|
2024-10-28 22:27:30 +01:00
|
|
|
public function visitsForNonDefaultDomainAreReturnedAsExpected(ApiKey|null $apiKey): void
|
2022-04-23 11:02:51 +02:00
|
|
|
{
|
|
|
|
|
$domain = 'foo.com';
|
2022-10-23 21:05:13 +02:00
|
|
|
$repo = $this->createMock(DomainRepository::class);
|
|
|
|
|
$repo->expects($this->once())->method('domainExists')->with($domain, $apiKey)->willReturn(true);
|
2022-04-23 11:02:51 +02:00
|
|
|
|
2023-11-29 12:34:13 +01:00
|
|
|
$list = array_map(
|
2024-11-11 08:51:55 +01:00
|
|
|
static fn () => Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::empty()),
|
2023-11-29 12:34:13 +01:00
|
|
|
range(0, 1),
|
|
|
|
|
);
|
2025-12-15 14:17:36 +01:00
|
|
|
$repo2 = $this->createStub(VisitRepository::class);
|
2025-02-13 10:35:58 +01:00
|
|
|
$repo2->method('findVisitsByDomain')->willReturn($list);
|
|
|
|
|
$repo2->method('countVisitsByDomain')->willReturn(1);
|
2022-10-23 21:05:13 +02:00
|
|
|
|
2026-05-22 08:42:47 +02:00
|
|
|
$this->em
|
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
|
->method('getRepository')
|
|
|
|
|
->willReturnMap([
|
|
|
|
|
[Domain::class, $repo],
|
|
|
|
|
[Visit::class, $repo2],
|
|
|
|
|
]);
|
2022-04-23 11:02:51 +02:00
|
|
|
|
|
|
|
|
$paginator = $this->helper->visitsForDomain($domain, new VisitsParams(), $apiKey);
|
|
|
|
|
|
|
|
|
|
self::assertEquals($list, ArrayUtils::iteratorToArray($paginator->getCurrentPageResults()));
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-18 10:41:24 +02:00
|
|
|
#[Test, DataProviderExternal(ApiKeyDataProviders::class, 'adminApiKeysProvider')]
|
2024-10-28 22:27:30 +01:00
|
|
|
public function visitsForDefaultDomainAreReturnedAsExpected(ApiKey|null $apiKey): void
|
2022-04-23 11:02:51 +02:00
|
|
|
{
|
2022-10-23 21:05:13 +02:00
|
|
|
$repo = $this->createMock(DomainRepository::class);
|
|
|
|
|
$repo->expects($this->never())->method('domainExists');
|
2022-04-23 11:02:51 +02:00
|
|
|
|
2023-11-29 12:34:13 +01:00
|
|
|
$list = array_map(
|
2024-11-11 08:51:55 +01:00
|
|
|
static fn () => Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::empty()),
|
2023-11-29 12:34:13 +01:00
|
|
|
range(0, 1),
|
|
|
|
|
);
|
2025-12-15 14:17:36 +01:00
|
|
|
$repo2 = $this->createStub(VisitRepository::class);
|
2025-02-13 10:35:58 +01:00
|
|
|
$repo2->method('findVisitsByDomain')->willReturn($list);
|
|
|
|
|
$repo2->method('countVisitsByDomain')->willReturn(1);
|
2022-10-23 21:05:13 +02:00
|
|
|
|
2026-05-22 08:42:47 +02:00
|
|
|
$this->em
|
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
|
->method('getRepository')
|
|
|
|
|
->willReturnMap([
|
|
|
|
|
[Domain::class, $repo],
|
|
|
|
|
[Visit::class, $repo2],
|
|
|
|
|
]);
|
2022-04-23 11:02:51 +02:00
|
|
|
|
2024-10-28 08:36:06 +01:00
|
|
|
$paginator = $this->helper->visitsForDomain(Domain::DEFAULT_AUTHORITY, new VisitsParams(), $apiKey);
|
2022-04-23 11:02:51 +02:00
|
|
|
|
|
|
|
|
self::assertEquals($list, ArrayUtils::iteratorToArray($paginator->getCurrentPageResults()));
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-09 20:42:18 +01:00
|
|
|
#[Test]
|
2021-02-09 22:40:40 +01:00
|
|
|
public function orphanVisitsAreReturnedAsExpected(): void
|
|
|
|
|
{
|
2024-11-11 08:51:55 +01:00
|
|
|
$list = array_map(static fn () => Visit::forBasePath(Visitor::empty()), range(0, 3));
|
2022-10-23 21:05:13 +02:00
|
|
|
$repo = $this->createMock(VisitRepository::class);
|
2026-05-22 18:09:59 +02:00
|
|
|
$repo
|
|
|
|
|
->expects($this->once())
|
2026-05-22 08:42:47 +02:00
|
|
|
->method('countOrphanVisits')
|
|
|
|
|
->with(
|
|
|
|
|
$this->isInstanceOf(OrphanVisitsCountFiltering::class),
|
|
|
|
|
)
|
|
|
|
|
->willReturn(count($list));
|
2026-05-22 18:09:59 +02:00
|
|
|
$repo
|
|
|
|
|
->expects($this->once())
|
2026-05-22 08:42:47 +02:00
|
|
|
->method('findOrphanVisits')
|
|
|
|
|
->with(
|
|
|
|
|
$this->isInstanceOf(OrphanVisitsListFiltering::class),
|
|
|
|
|
)
|
|
|
|
|
->willReturn($list);
|
2022-10-23 21:05:13 +02:00
|
|
|
$this->em->expects($this->once())->method('getRepository')->with(Visit::class)->willReturn($repo);
|
2021-02-09 22:40:40 +01:00
|
|
|
|
2024-02-10 17:51:42 +01:00
|
|
|
$paginator = $this->helper->orphanVisits(new OrphanVisitsParams());
|
2021-02-09 22:40:40 +01:00
|
|
|
|
|
|
|
|
self::assertEquals($list, ArrayUtils::iteratorToArray($paginator->getCurrentPageResults()));
|
|
|
|
|
}
|
2022-01-16 12:29:36 +01:00
|
|
|
|
2023-02-09 20:42:18 +01:00
|
|
|
#[Test]
|
2022-01-16 12:29:36 +01:00
|
|
|
public function nonOrphanVisitsAreReturnedAsExpected(): void
|
|
|
|
|
{
|
2023-11-29 12:34:13 +01:00
|
|
|
$list = array_map(
|
2024-11-11 08:51:55 +01:00
|
|
|
static fn () => Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::empty()),
|
2023-11-29 12:34:13 +01:00
|
|
|
range(0, 3),
|
|
|
|
|
);
|
2022-10-23 21:05:13 +02:00
|
|
|
$repo = $this->createMock(VisitRepository::class);
|
2026-05-22 18:09:59 +02:00
|
|
|
$repo
|
|
|
|
|
->expects($this->once())
|
2026-05-22 08:42:47 +02:00
|
|
|
->method('countNonOrphanVisits')
|
|
|
|
|
->with(
|
|
|
|
|
$this->isInstanceOf(WithDOmainVisitsCountFiltering::class),
|
|
|
|
|
)
|
|
|
|
|
->willReturn(count($list));
|
2026-05-22 18:09:59 +02:00
|
|
|
$repo
|
|
|
|
|
->expects($this->once())
|
2026-05-22 08:42:47 +02:00
|
|
|
->method('findNonOrphanVisits')
|
|
|
|
|
->with(
|
|
|
|
|
$this->isInstanceOf(WithDOmainVisitsListFiltering::class),
|
|
|
|
|
)
|
|
|
|
|
->willReturn($list);
|
2022-10-23 21:05:13 +02:00
|
|
|
$this->em->expects($this->once())->method('getRepository')->with(Visit::class)->willReturn($repo);
|
2022-01-16 12:29:36 +01:00
|
|
|
|
2025-10-28 10:55:06 +01:00
|
|
|
$paginator = $this->helper->nonOrphanVisits(new WithDomainVisitsParams());
|
2022-01-16 12:29:36 +01:00
|
|
|
|
|
|
|
|
self::assertEquals($list, ArrayUtils::iteratorToArray($paginator->getCurrentPageResults()));
|
|
|
|
|
}
|
2020-05-01 11:57:46 +02:00
|
|
|
}
|