Completed
Push — develop ( 8109ce...b15e90 )
by Alejandro
17s queued 12s
created

allDomainsAreProperlyPrinted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 22
rs 9.7
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\CLI\Command\Domain;
6
7
use PHPUnit\Framework\TestCase;
8
use Prophecy\Prophecy\ObjectProphecy;
9
use Shlinkio\Shlink\CLI\Command\Domain\ListDomainsCommand;
10
use Shlinkio\Shlink\CLI\Util\ExitCodes;
11
use Shlinkio\Shlink\Core\Domain\DomainServiceInterface;
12
use Shlinkio\Shlink\Core\Entity\Domain;
13
use Symfony\Component\Console\Application;
14
use Symfony\Component\Console\Tester\CommandTester;
15
16
class ListDomainsCommandTest extends TestCase
17
{
18
    private CommandTester $commandTester;
19
    private ObjectProphecy $domainService;
20
21
    public function setUp(): void
22
    {
23
        $this->domainService = $this->prophesize(DomainServiceInterface::class);
24
25
        $command = new ListDomainsCommand($this->domainService->reveal(), 'foo.com');
26
        $app = new Application();
27
        $app->add($command);
28
29
        $this->commandTester = new CommandTester($command);
30
    }
31
32
    /** @test */
33
    public function allDomainsAreProperlyPrinted(): void
34
    {
35
        $expectedOutput = <<<OUTPUT
36
        +---------+------------+
37
        | Domain  | Is default |
38
        +---------+------------+
39
        | foo.com | Yes        |
40
        | bar.com | No         |
41
        | baz.com | No         |
42
        +---------+------------+
43
44
        OUTPUT;
45
        $listDomains = $this->domainService->listDomainsWithout('foo.com')->willReturn([
46
            new Domain('bar.com'),
47
            new Domain('baz.com'),
48
        ]);
49
50
        $this->commandTester->execute([]);
51
52
        self::assertEquals($expectedOutput, $this->commandTester->getDisplay());
53
        self::assertEquals(ExitCodes::EXIT_SUCCESS, $this->commandTester->getStatusCode());
54
        $listDomains->shouldHaveBeenCalledOnce();
55
    }
56
}
57