ListDomainsActionTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkioTest\Shlink\Rest\Action\Domain;
6
7
use Laminas\Diactoros\Response\JsonResponse;
8
use Laminas\Diactoros\ServerRequestFactory;
9
use PHPUnit\Framework\TestCase;
10
use Prophecy\PhpUnit\ProphecyTrait;
11
use Prophecy\Prophecy\ObjectProphecy;
12
use Shlinkio\Shlink\Core\Domain\DomainServiceInterface;
13
use Shlinkio\Shlink\Core\Entity\Domain;
14
use Shlinkio\Shlink\Rest\Action\Domain\ListDomainsAction;
15
16
class ListDomainsActionTest extends TestCase
17
{
18
    use ProphecyTrait;
19
20
    private ListDomainsAction $action;
21
    private ObjectProphecy $domainService;
22
23
    public function setUp(): void
24
    {
25
        $this->domainService = $this->prophesize(DomainServiceInterface::class);
26
        $this->action = new ListDomainsAction($this->domainService->reveal(), 'foo.com');
27
    }
28
29
    /** @test */
30
    public function domainsAreProperlyListed(): void
31
    {
32
        $listDomains = $this->domainService->listDomainsWithout('foo.com')->willReturn([
33
            new Domain('bar.com'),
34
            new Domain('baz.com'),
35
        ]);
36
37
        /** @var JsonResponse $resp */
38
        $resp = $this->action->handle(ServerRequestFactory::fromGlobals());
39
        $payload = $resp->getPayload();
40
41
        self::assertEquals([
42
            'domains' => [
43
                'data' => [
44
                    [
45
                        'domain' => 'foo.com',
46
                        'isDefault' => true,
47
                    ],
48
                    [
49
                        'domain' => 'bar.com',
50
                        'isDefault' => false,
51
                    ],
52
                    [
53
                        'domain' => 'baz.com',
54
                        'isDefault' => false,
55
                    ],
56
                ],
57
            ],
58
        ], $payload);
59
        $listDomains->shouldHaveBeenCalledOnce();
60
    }
61
}
62