shlink/module/Rest/test/Action/Domain/ListDomainsActionTest.php

54 lines
1.7 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Rest\Action\Domain;
use Laminas\Diactoros\Response\JsonResponse;
use Laminas\Diactoros\ServerRequestFactory;
use PHPUnit\Framework\TestCase;
2020-11-02 13:50:19 +03:00
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Core\Domain\DomainServiceInterface;
use Shlinkio\Shlink\Core\Domain\Model\DomainItem;
use Shlinkio\Shlink\Core\Entity\Domain;
use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions;
use Shlinkio\Shlink\Rest\Action\Domain\ListDomainsAction;
2021-01-04 17:55:59 +03:00
use Shlinkio\Shlink\Rest\Entity\ApiKey;
class ListDomainsActionTest extends TestCase
{
2020-11-02 13:50:19 +03:00
use ProphecyTrait;
private ListDomainsAction $action;
private ObjectProphecy $domainService;
public function setUp(): void
{
$this->domainService = $this->prophesize(DomainServiceInterface::class);
2021-01-04 17:55:59 +03:00
$this->action = new ListDomainsAction($this->domainService->reveal());
}
/** @test */
public function domainsAreProperlyListed(): void
{
$apiKey = ApiKey::create();
$domains = [
DomainItem::forDefaultDomain('bar.com', new NotFoundRedirectOptions()),
2021-07-22 21:48:58 +03:00
DomainItem::forExistingDomain(Domain::withAuthority('baz.com')),
];
2021-01-04 17:55:59 +03:00
$listDomains = $this->domainService->listDomains($apiKey)->willReturn($domains);
/** @var JsonResponse $resp */
2021-01-04 17:55:59 +03:00
$resp = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute(ApiKey::class, $apiKey));
$payload = $resp->getPayload();
self::assertEquals([
'domains' => [
'data' => $domains,
],
], $payload);
$listDomains->shouldHaveBeenCalledOnce();
}
}