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;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2020-11-02 13:50:19 +03:00
|
|
|
use Prophecy\PhpUnit\ProphecyTrait;
|
2020-09-27 11:11:41 +03:00
|
|
|
use Prophecy\Prophecy\ObjectProphecy;
|
|
|
|
use Shlinkio\Shlink\Core\Domain\DomainServiceInterface;
|
2021-01-04 17:02:37 +03:00
|
|
|
use Shlinkio\Shlink\Core\Domain\Model\DomainItem;
|
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
|
|
|
|
{
|
2020-11-02 13:50:19 +03:00
|
|
|
use ProphecyTrait;
|
|
|
|
|
2020-09-27 11:11:41 +03:00
|
|
|
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());
|
2020-09-27 11:11:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
public function domainsAreProperlyListed(): void
|
|
|
|
{
|
2021-01-04 17:55:59 +03:00
|
|
|
$apiKey = new ApiKey();
|
2021-01-04 17:02:37 +03:00
|
|
|
$domains = [
|
|
|
|
new DomainItem('bar.com', true),
|
|
|
|
new DomainItem('baz.com', false),
|
|
|
|
];
|
2021-01-04 17:55:59 +03:00
|
|
|
$listDomains = $this->domainService->listDomains($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,
|
2020-09-27 11:11:41 +03:00
|
|
|
],
|
|
|
|
], $payload);
|
|
|
|
$listDomains->shouldHaveBeenCalledOnce();
|
|
|
|
}
|
|
|
|
}
|