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