2022-01-16 14:24:02 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Rest\Action\Visit;
|
|
|
|
|
|
|
|
use Laminas\Diactoros\Response\JsonResponse;
|
|
|
|
use Laminas\Diactoros\ServerRequestFactory;
|
|
|
|
use Pagerfanta\Adapter\ArrayAdapter;
|
2022-10-23 23:24:06 +03:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2022-01-16 14:24:02 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Shlinkio\Shlink\Common\Paginator\Paginator;
|
2022-09-23 19:05:17 +03:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Model\VisitsParams;
|
2022-01-16 14:24:02 +03:00
|
|
|
use Shlinkio\Shlink\Core\Visit\VisitsStatsHelperInterface;
|
|
|
|
use Shlinkio\Shlink\Rest\Action\Visit\NonOrphanVisitsAction;
|
|
|
|
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
|
|
|
|
|
|
|
class NonOrphanVisitsActionTest extends TestCase
|
|
|
|
{
|
|
|
|
private NonOrphanVisitsAction $action;
|
2022-10-24 20:53:13 +03:00
|
|
|
private MockObject & VisitsStatsHelperInterface $visitsHelper;
|
2022-01-16 14:24:02 +03:00
|
|
|
|
2022-09-11 13:02:49 +03:00
|
|
|
protected function setUp(): void
|
2022-01-16 14:24:02 +03:00
|
|
|
{
|
2022-10-23 23:24:06 +03:00
|
|
|
$this->visitsHelper = $this->createMock(VisitsStatsHelperInterface::class);
|
|
|
|
$this->action = new NonOrphanVisitsAction($this->visitsHelper);
|
2022-01-16 14:24:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
public function requestIsHandled(): void
|
|
|
|
{
|
|
|
|
$apiKey = ApiKey::create();
|
2022-10-23 23:24:06 +03:00
|
|
|
$this->visitsHelper->expects($this->once())->method('nonOrphanVisits')->with(
|
|
|
|
$this->isInstanceOf(VisitsParams::class),
|
|
|
|
$apiKey,
|
|
|
|
)->willReturn(new Paginator(new ArrayAdapter([])));
|
2022-01-16 14:24:02 +03:00
|
|
|
|
|
|
|
/** @var JsonResponse $response */
|
|
|
|
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute(ApiKey::class, $apiKey));
|
|
|
|
$payload = $response->getPayload();
|
|
|
|
|
|
|
|
self::assertEquals(200, $response->getStatusCode());
|
|
|
|
self::assertArrayHasKey('visits', $payload);
|
|
|
|
}
|
|
|
|
}
|