2023-01-02 05:45:08 -06:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioApiTest\Shlink\Rest\Action;
|
|
|
|
|
2023-02-09 13:42:18 -06:00
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2023-01-02 05:45:08 -06:00
|
|
|
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;
|
|
|
|
|
|
|
|
class VisitStatsTest extends ApiTestCase
|
|
|
|
{
|
2023-02-09 13:42:18 -06:00
|
|
|
#[Test, DataProvider('provideApiKeysAndResults')]
|
2023-01-02 05:45:08 -06:00
|
|
|
public function expectedStatsAreReturned(string $apiKey, array $expectedPayload): void
|
|
|
|
{
|
|
|
|
$resp = $this->callApiWithKey(self::METHOD_GET, '/visits', apiKey: $apiKey);
|
|
|
|
$payload = $this->getJsonResponsePayload($resp);
|
|
|
|
|
|
|
|
self::assertEquals(['visits' => $expectedPayload], $payload);
|
|
|
|
}
|
|
|
|
|
2023-02-09 02:32:38 -06:00
|
|
|
public static function provideApiKeysAndResults(): iterable
|
2023-01-02 05:45:08 -06:00
|
|
|
{
|
|
|
|
yield 'valid API key' => ['valid_api_key', [
|
|
|
|
'nonOrphanVisits' => [
|
|
|
|
'total' => 7,
|
|
|
|
'nonBots' => 6,
|
|
|
|
'bots' => 1,
|
|
|
|
],
|
|
|
|
'orphanVisits' => [
|
|
|
|
'total' => 3,
|
|
|
|
'nonBots' => 2,
|
|
|
|
'bots' => 1,
|
|
|
|
],
|
|
|
|
'visitsCount' => 7,
|
|
|
|
'orphanVisitsCount' => 3,
|
|
|
|
]];
|
|
|
|
yield 'domain-only API key' => ['domain_api_key', [
|
|
|
|
'nonOrphanVisits' => [
|
|
|
|
'total' => 0,
|
|
|
|
'nonBots' => 0,
|
|
|
|
'bots' => 0,
|
|
|
|
],
|
|
|
|
'orphanVisits' => [
|
|
|
|
'total' => 3,
|
|
|
|
'nonBots' => 2,
|
|
|
|
'bots' => 1,
|
|
|
|
],
|
|
|
|
'visitsCount' => 0,
|
|
|
|
'orphanVisitsCount' => 3,
|
|
|
|
]];
|
|
|
|
yield 'author API key' => ['author_api_key', [
|
|
|
|
'nonOrphanVisits' => [
|
|
|
|
'total' => 5,
|
|
|
|
'nonBots' => 4,
|
|
|
|
'bots' => 1,
|
|
|
|
],
|
|
|
|
'orphanVisits' => [
|
|
|
|
'total' => 3,
|
|
|
|
'nonBots' => 2,
|
|
|
|
'bots' => 1,
|
|
|
|
],
|
|
|
|
'visitsCount' => 5,
|
|
|
|
'orphanVisitsCount' => 3,
|
|
|
|
]];
|
|
|
|
}
|
|
|
|
}
|