2020-09-27 13:48:24 +03: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;
|
2021-07-22 18:49:37 +03:00
|
|
|
use Shlinkio\Shlink\Core\Config\NotFoundRedirects;
|
2020-09-27 13:48:24 +03:00
|
|
|
use Shlinkio\Shlink\Core\Domain\DomainServiceInterface;
|
2021-01-04 17:02:37 +03:00
|
|
|
use Shlinkio\Shlink\Core\Domain\Model\DomainItem;
|
2021-07-21 22:09:33 +03:00
|
|
|
use Shlinkio\Shlink\Core\Entity\Domain;
|
|
|
|
use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions;
|
2021-04-08 14:42:56 +03:00
|
|
|
use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait;
|
2020-09-27 13:48:24 +03:00
|
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
|
|
|
|
|
|
|
class ListDomainsCommandTest extends TestCase
|
|
|
|
{
|
2021-04-08 14:42:56 +03:00
|
|
|
use CliTestUtilsTrait;
|
2020-11-02 13:50:19 +03:00
|
|
|
|
2020-09-27 13:48:24 +03:00
|
|
|
private CommandTester $commandTester;
|
|
|
|
private ObjectProphecy $domainService;
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
$this->domainService = $this->prophesize(DomainServiceInterface::class);
|
2021-04-08 14:42:56 +03:00
|
|
|
$this->commandTester = $this->testerForCommand(new ListDomainsCommand($this->domainService->reveal()));
|
2020-09-27 13:48:24 +03:00
|
|
|
}
|
|
|
|
|
2021-07-22 18:49:37 +03:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @dataProvider provideInputsAndOutputs
|
|
|
|
*/
|
|
|
|
public function allDomainsAreProperlyPrinted(array $input, string $expectedOutput): void
|
2020-09-27 13:48:24 +03:00
|
|
|
{
|
2021-07-22 21:48:58 +03:00
|
|
|
$bazDomain = Domain::withAuthority('baz.com');
|
2021-08-03 15:08:36 +03:00
|
|
|
$bazDomain->configureNotFoundRedirects(NotFoundRedirects::withRedirects(
|
2021-07-22 18:49:37 +03:00
|
|
|
null,
|
|
|
|
'https://foo.com/baz-domain/regular',
|
|
|
|
'https://foo.com/baz-domain/invalid',
|
|
|
|
));
|
|
|
|
|
|
|
|
$listDomains = $this->domainService->listDomains()->willReturn([
|
|
|
|
DomainItem::forDefaultDomain('foo.com', new NotFoundRedirectOptions([
|
|
|
|
'base_url' => 'https://foo.com/default/base',
|
|
|
|
'invalid_short_url' => 'https://foo.com/default/invalid',
|
|
|
|
])),
|
2021-12-09 14:32:02 +03:00
|
|
|
DomainItem::forNonDefaultDomain(Domain::withAuthority('bar.com')),
|
|
|
|
DomainItem::forNonDefaultDomain($bazDomain),
|
2021-07-22 18:49:37 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->commandTester->execute($input);
|
|
|
|
|
|
|
|
self::assertEquals($expectedOutput, $this->commandTester->getDisplay());
|
|
|
|
self::assertEquals(ExitCodes::EXIT_SUCCESS, $this->commandTester->getStatusCode());
|
|
|
|
$listDomains->shouldHaveBeenCalledOnce();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideInputsAndOutputs(): iterable
|
|
|
|
{
|
|
|
|
$withoutRedirectsOutput = <<<OUTPUT
|
2020-09-27 13:48:24 +03:00
|
|
|
+---------+------------+
|
|
|
|
| Domain | Is default |
|
|
|
|
+---------+------------+
|
|
|
|
| foo.com | Yes |
|
|
|
|
| bar.com | No |
|
|
|
|
| baz.com | No |
|
|
|
|
+---------+------------+
|
|
|
|
|
|
|
|
OUTPUT;
|
2021-07-22 18:49:37 +03:00
|
|
|
$withRedirectsOutput = <<<OUTPUT
|
|
|
|
+---------+------------+---------------------------------------------------------+
|
|
|
|
| Domain | Is default | "Not found" redirects |
|
|
|
|
+---------+------------+---------------------------------------------------------+
|
|
|
|
| foo.com | Yes | * Base URL: https://foo.com/default/base |
|
|
|
|
| | | * Regular 404: N/A |
|
|
|
|
| | | * Invalid short URL: https://foo.com/default/invalid |
|
2021-08-03 11:21:42 +03:00
|
|
|
+---------+------------+---------------------------------------------------------+
|
2021-07-22 18:49:37 +03:00
|
|
|
| bar.com | No | * Base URL: N/A |
|
|
|
|
| | | * Regular 404: N/A |
|
|
|
|
| | | * Invalid short URL: N/A |
|
2021-08-03 11:21:42 +03:00
|
|
|
+---------+------------+---------------------------------------------------------+
|
2021-07-22 18:49:37 +03:00
|
|
|
| baz.com | No | * Base URL: N/A |
|
|
|
|
| | | * Regular 404: https://foo.com/baz-domain/regular |
|
|
|
|
| | | * Invalid short URL: https://foo.com/baz-domain/invalid |
|
|
|
|
+---------+------------+---------------------------------------------------------+
|
2020-09-27 13:48:24 +03:00
|
|
|
|
2021-07-22 18:49:37 +03:00
|
|
|
OUTPUT;
|
2020-09-27 13:48:24 +03:00
|
|
|
|
2021-07-22 18:49:37 +03:00
|
|
|
yield 'no args' => [[], $withoutRedirectsOutput];
|
|
|
|
yield 'no show redirects' => [['--show-redirects' => false], $withoutRedirectsOutput];
|
|
|
|
yield 'show redirects' => [['--show-redirects' => true], $withRedirectsOutput];
|
2020-09-27 13:48:24 +03:00
|
|
|
}
|
|
|
|
}
|