2020-09-27 05:48:24 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\CLI\Command\Domain;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Prophecy\Prophecy\ObjectProphecy;
|
|
|
|
use Shlinkio\Shlink\CLI\Command\Domain\ListDomainsCommand;
|
|
|
|
use Shlinkio\Shlink\CLI\Util\ExitCodes;
|
|
|
|
use Shlinkio\Shlink\Core\Domain\DomainServiceInterface;
|
2021-01-04 08:02:37 -06:00
|
|
|
use Shlinkio\Shlink\Core\Domain\Model\DomainItem;
|
2021-04-08 06:42:56 -05:00
|
|
|
use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait;
|
2020-09-27 05:48:24 -05:00
|
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
|
|
|
|
|
|
|
class ListDomainsCommandTest extends TestCase
|
|
|
|
{
|
2021-04-08 06:42:56 -05:00
|
|
|
use CliTestUtilsTrait;
|
2020-11-02 04:50:19 -06:00
|
|
|
|
2020-09-27 05:48:24 -05:00
|
|
|
private CommandTester $commandTester;
|
|
|
|
private ObjectProphecy $domainService;
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
$this->domainService = $this->prophesize(DomainServiceInterface::class);
|
2021-04-08 06:42:56 -05:00
|
|
|
$this->commandTester = $this->testerForCommand(new ListDomainsCommand($this->domainService->reveal()));
|
2020-09-27 05:48:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
public function allDomainsAreProperlyPrinted(): void
|
|
|
|
{
|
|
|
|
$expectedOutput = <<<OUTPUT
|
|
|
|
+---------+------------+
|
|
|
|
| Domain | Is default |
|
|
|
|
+---------+------------+
|
|
|
|
| foo.com | Yes |
|
|
|
|
| bar.com | No |
|
|
|
|
| baz.com | No |
|
|
|
|
+---------+------------+
|
|
|
|
|
|
|
|
OUTPUT;
|
2021-01-04 08:16:51 -06:00
|
|
|
$listDomains = $this->domainService->listDomains()->willReturn([
|
2021-01-04 08:02:37 -06:00
|
|
|
new DomainItem('foo.com', true),
|
|
|
|
new DomainItem('bar.com', false),
|
|
|
|
new DomainItem('baz.com', false),
|
2020-09-27 05:48:24 -05:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->commandTester->execute([]);
|
|
|
|
|
|
|
|
self::assertEquals($expectedOutput, $this->commandTester->getDisplay());
|
|
|
|
self::assertEquals(ExitCodes::EXIT_SUCCESS, $this->commandTester->getStatusCode());
|
|
|
|
$listDomains->shouldHaveBeenCalledOnce();
|
|
|
|
}
|
|
|
|
}
|