2022-04-23 12:07:10 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Rest\Action\Visit;
|
|
|
|
|
|
|
|
use Laminas\Diactoros\ServerRequestFactory;
|
|
|
|
use Pagerfanta\Adapter\ArrayAdapter;
|
2022-10-23 23:22:14 +03:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2022-04-23 12:07:10 +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-04-23 12:07:10 +03:00
|
|
|
use Shlinkio\Shlink\Core\Visit\VisitsStatsHelperInterface;
|
|
|
|
use Shlinkio\Shlink\Rest\Action\Visit\DomainVisitsAction;
|
|
|
|
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
|
|
|
|
|
|
|
class DomainVisitsActionTest extends TestCase
|
|
|
|
{
|
|
|
|
private DomainVisitsAction $action;
|
2022-10-24 20:53:13 +03:00
|
|
|
private MockObject & VisitsStatsHelperInterface $visitsHelper;
|
2022-04-23 12:07:10 +03:00
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
2022-10-23 23:22:14 +03:00
|
|
|
$this->visitsHelper = $this->createMock(VisitsStatsHelperInterface::class);
|
|
|
|
$this->action = new DomainVisitsAction($this->visitsHelper, 'the_default.com');
|
2022-04-23 12:07:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideDomainAuthorities
|
|
|
|
*/
|
|
|
|
public function providingCorrectDomainReturnsVisits(string $providedDomain, string $expectedDomain): void
|
|
|
|
{
|
|
|
|
$apiKey = ApiKey::create();
|
2022-10-23 23:22:14 +03:00
|
|
|
$this->visitsHelper->expects($this->once())->method('visitsForDomain')->with(
|
2022-04-23 12:07:10 +03:00
|
|
|
$expectedDomain,
|
2022-10-23 23:22:14 +03:00
|
|
|
$this->isInstanceOf(VisitsParams::class),
|
2022-04-23 12:07:10 +03:00
|
|
|
$apiKey,
|
|
|
|
)->willReturn(new Paginator(new ArrayAdapter([])));
|
|
|
|
|
|
|
|
$response = $this->action->handle(
|
|
|
|
ServerRequestFactory::fromGlobals()->withAttribute('domain', $providedDomain)
|
|
|
|
->withAttribute(ApiKey::class, $apiKey),
|
|
|
|
);
|
|
|
|
|
|
|
|
self::assertEquals(200, $response->getStatusCode());
|
|
|
|
}
|
|
|
|
|
2023-02-09 11:32:38 +03:00
|
|
|
public static function provideDomainAuthorities(): iterable
|
2022-04-23 12:07:10 +03:00
|
|
|
{
|
|
|
|
yield 'no default domain' => ['foo.com', 'foo.com'];
|
|
|
|
yield 'default domain' => ['the_default.com', 'DEFAULT'];
|
|
|
|
yield 'DEFAULT keyword' => ['DEFAULT', 'DEFAULT'];
|
|
|
|
}
|
|
|
|
}
|