2020-09-27 11:11:41 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Rest\Action\Domain;
|
|
|
|
|
|
|
|
use Laminas\Diactoros\Response\JsonResponse;
|
|
|
|
use Laminas\Diactoros\ServerRequestFactory;
|
2022-10-23 23:06:48 +03:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2020-09-27 11:11:41 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2021-12-09 14:32:02 +03:00
|
|
|
use Shlinkio\Shlink\Core\Config\NotFoundRedirects;
|
2020-09-27 11:11:41 +03:00
|
|
|
use Shlinkio\Shlink\Core\Domain\DomainServiceInterface;
|
2022-09-23 20:03:32 +03:00
|
|
|
use Shlinkio\Shlink\Core\Domain\Entity\Domain;
|
2021-01-04 17:02:37 +03:00
|
|
|
use Shlinkio\Shlink\Core\Domain\Model\DomainItem;
|
2021-07-21 22:09:33 +03:00
|
|
|
use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions;
|
2020-09-27 11:11:41 +03:00
|
|
|
use Shlinkio\Shlink\Rest\Action\Domain\ListDomainsAction;
|
2021-01-04 17:55:59 +03:00
|
|
|
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
2020-09-27 11:11:41 +03:00
|
|
|
|
|
|
|
class ListDomainsActionTest extends TestCase
|
|
|
|
{
|
|
|
|
private ListDomainsAction $action;
|
2022-10-24 20:53:13 +03:00
|
|
|
private MockObject & DomainServiceInterface $domainService;
|
2021-12-09 14:11:09 +03:00
|
|
|
private NotFoundRedirectOptions $options;
|
2020-09-27 11:11:41 +03:00
|
|
|
|
2022-09-11 13:02:49 +03:00
|
|
|
protected function setUp(): void
|
2020-09-27 11:11:41 +03:00
|
|
|
{
|
2022-10-23 23:06:48 +03:00
|
|
|
$this->domainService = $this->createMock(DomainServiceInterface::class);
|
2021-12-09 14:11:09 +03:00
|
|
|
$this->options = new NotFoundRedirectOptions();
|
2022-10-23 23:06:48 +03:00
|
|
|
$this->action = new ListDomainsAction($this->domainService, $this->options);
|
2020-09-27 11:11:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
public function domainsAreProperlyListed(): void
|
|
|
|
{
|
2021-03-14 11:59:35 +03:00
|
|
|
$apiKey = ApiKey::create();
|
2021-01-04 17:02:37 +03:00
|
|
|
$domains = [
|
2021-07-21 22:09:33 +03:00
|
|
|
DomainItem::forDefaultDomain('bar.com', new NotFoundRedirectOptions()),
|
2021-12-09 14:32:02 +03:00
|
|
|
DomainItem::forNonDefaultDomain(Domain::withAuthority('baz.com')),
|
2021-01-04 17:02:37 +03:00
|
|
|
];
|
2022-10-23 23:06:48 +03:00
|
|
|
$this->domainService->expects($this->once())->method('listDomains')->with($apiKey)->willReturn($domains);
|
2020-09-27 11:11:41 +03:00
|
|
|
|
|
|
|
/** @var JsonResponse $resp */
|
2021-01-04 17:55:59 +03:00
|
|
|
$resp = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute(ApiKey::class, $apiKey));
|
2020-09-27 11:11:41 +03:00
|
|
|
$payload = $resp->getPayload();
|
|
|
|
|
|
|
|
self::assertEquals([
|
|
|
|
'domains' => [
|
2021-01-04 17:02:37 +03:00
|
|
|
'data' => $domains,
|
2021-12-09 14:32:02 +03:00
|
|
|
'defaultRedirects' => NotFoundRedirects::fromConfig($this->options),
|
2020-09-27 11:11:41 +03:00
|
|
|
],
|
|
|
|
], $payload);
|
|
|
|
}
|
|
|
|
}
|