mirror of
https://github.com/shlinkio/shlink.git
synced 2026-10-12 13:31:58 -05:00
Added startDate and endDate params to ListShortUrlsCommand
This commit is contained in:
1 parent
8142801f1f
commit
5616579131
6 files changed
+215
-58
No files matched your search
@@ -22,6 +22,8 @@ use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Zend\Paginator\Adapter\ArrayAdapter;
|
||||
use Zend\Paginator\Paginator;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
class GetVisitsCommandTest extends TestCase
|
||||
{
|
||||
/** @var CommandTester */
|
||||
@@ -39,7 +41,7 @@ class GetVisitsCommandTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function noDateFlagsTriesToListWithoutDateRange()
|
||||
public function noDateFlagsTriesToListWithoutDateRange(): void
|
||||
{
|
||||
$shortCode = 'abc123';
|
||||
$this->visitsTracker->info($shortCode, new VisitsParams(new DateRange(null, null)))->willReturn(
|
||||
@@ -50,7 +52,7 @@ class GetVisitsCommandTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function providingDateFlagsTheListGetsFiltered()
|
||||
public function providingDateFlagsTheListGetsFiltered(): void
|
||||
{
|
||||
$shortCode = 'abc123';
|
||||
$startDate = '2016-01-01';
|
||||
@@ -69,6 +71,27 @@ class GetVisitsCommandTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function providingInvalidDatesPrintsWarning(): void
|
||||
{
|
||||
$shortCode = 'abc123';
|
||||
$startDate = 'foo';
|
||||
$info = $this->visitsTracker->info($shortCode, new VisitsParams(new DateRange()))
|
||||
->willReturn(new Paginator(new ArrayAdapter([])));
|
||||
|
||||
$this->commandTester->execute([
|
||||
'shortCode' => $shortCode,
|
||||
'--startDate' => $startDate,
|
||||
]);
|
||||
$output = $this->commandTester->getDisplay();
|
||||
|
||||
$info->shouldHaveBeenCalledOnce();
|
||||
$this->assertStringContainsString(
|
||||
sprintf('Ignored provided "startDate" since its value "%s" is not a valid date', $startDate),
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function outputIsProperlyGenerated(): void
|
||||
{
|
||||
|
||||
@@ -4,10 +4,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\CLI\Command\ShortUrl;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Shlinkio\Shlink\CLI\Command\ShortUrl\ListShortUrlsCommand;
|
||||
use Shlinkio\Shlink\Common\Util\DateRange;
|
||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||
use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface;
|
||||
use Symfony\Component\Console\Application;
|
||||
@@ -15,6 +17,8 @@ use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Zend\Paginator\Adapter\ArrayAdapter;
|
||||
use Zend\Paginator\Paginator;
|
||||
|
||||
use function explode;
|
||||
|
||||
class ListShortUrlsCommandTest extends TestCase
|
||||
{
|
||||
/** @var CommandTester */
|
||||
@@ -32,17 +36,7 @@ class ListShortUrlsCommandTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function noInputCallsListJustOnce()
|
||||
{
|
||||
$this->shortUrlService->listShortUrls(1, null, [], null)->willReturn(new Paginator(new ArrayAdapter()))
|
||||
->shouldBeCalledOnce();
|
||||
|
||||
$this->commandTester->setInputs(['n']);
|
||||
$this->commandTester->execute([]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function loadingMorePagesCallsListMoreTimes()
|
||||
public function loadingMorePagesCallsListMoreTimes(): void
|
||||
{
|
||||
// The paginator will return more than one page
|
||||
$data = [];
|
||||
@@ -64,7 +58,7 @@ class ListShortUrlsCommandTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function havingMorePagesButAnsweringNoCallsListJustOnce()
|
||||
public function havingMorePagesButAnsweringNoCallsListJustOnce(): void
|
||||
{
|
||||
// The paginator will return more than one page
|
||||
$data = [];
|
||||
@@ -72,8 +66,9 @@ class ListShortUrlsCommandTest extends TestCase
|
||||
$data[] = new ShortUrl('url_' . $i);
|
||||
}
|
||||
|
||||
$this->shortUrlService->listShortUrls(1, null, [], null)->willReturn(new Paginator(new ArrayAdapter($data)))
|
||||
->shouldBeCalledOnce();
|
||||
$this->shortUrlService->listShortUrls(1, null, [], null, new DateRange())
|
||||
->willReturn(new Paginator(new ArrayAdapter($data)))
|
||||
->shouldBeCalledOnce();
|
||||
|
||||
$this->commandTester->setInputs(['n']);
|
||||
$this->commandTester->execute([]);
|
||||
@@ -89,25 +84,82 @@ class ListShortUrlsCommandTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function passingPageWillMakeListStartOnThatPage()
|
||||
public function passingPageWillMakeListStartOnThatPage(): void
|
||||
{
|
||||
$page = 5;
|
||||
$this->shortUrlService->listShortUrls($page, null, [], null)->willReturn(new Paginator(new ArrayAdapter()))
|
||||
->shouldBeCalledOnce();
|
||||
$this->shortUrlService->listShortUrls($page, null, [], null, new DateRange())
|
||||
->willReturn(new Paginator(new ArrayAdapter()))
|
||||
->shouldBeCalledOnce();
|
||||
|
||||
$this->commandTester->setInputs(['y']);
|
||||
$this->commandTester->execute(['--page' => $page]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function ifTagsFlagIsProvidedTagsColumnIsIncluded()
|
||||
public function ifTagsFlagIsProvidedTagsColumnIsIncluded(): void
|
||||
{
|
||||
$this->shortUrlService->listShortUrls(1, null, [], null)->willReturn(new Paginator(new ArrayAdapter()))
|
||||
->shouldBeCalledOnce();
|
||||
$this->shortUrlService->listShortUrls(1, null, [], null, new DateRange())
|
||||
->willReturn(new Paginator(new ArrayAdapter()))
|
||||
->shouldBeCalledOnce();
|
||||
|
||||
$this->commandTester->setInputs(['y']);
|
||||
$this->commandTester->execute(['--showTags' => true]);
|
||||
$output = $this->commandTester->getDisplay();
|
||||
$this->assertStringContainsString('Tags', $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideArgs
|
||||
*/
|
||||
public function serviceIsInvokedWithProvidedArgs(
|
||||
array $commandArgs,
|
||||
?int $page,
|
||||
?string $searchTerm,
|
||||
array $tags,
|
||||
?DateRange $dateRange
|
||||
): void {
|
||||
$listShortUrls = $this->shortUrlService->listShortUrls($page, $searchTerm, $tags, null, $dateRange)
|
||||
->willReturn(new Paginator(new ArrayAdapter()));
|
||||
|
||||
$this->commandTester->setInputs(['n']);
|
||||
$this->commandTester->execute($commandArgs);
|
||||
|
||||
$listShortUrls->shouldHaveBeenCalledOnce();
|
||||
}
|
||||
|
||||
public function provideArgs(): iterable
|
||||
{
|
||||
yield [[], 1, null, [], new DateRange()];
|
||||
yield [['--page' => $page = 3], $page, null, [], new DateRange()];
|
||||
yield [['--searchTerm' => $searchTerm = 'search this'], 1, $searchTerm, [], new DateRange()];
|
||||
yield [
|
||||
['--page' => $page = 3, '--searchTerm' => $searchTerm = 'search this', '--tags' => $tags = 'foo,bar'],
|
||||
$page,
|
||||
$searchTerm,
|
||||
explode(',', $tags),
|
||||
new DateRange(),
|
||||
];
|
||||
yield [
|
||||
['--startDate' => $startDate = '2019-01-01'],
|
||||
1,
|
||||
null,
|
||||
[],
|
||||
new DateRange(Chronos::parse($startDate)),
|
||||
];
|
||||
yield [
|
||||
['--endDate' => $endDate = '2020-05-23'],
|
||||
1,
|
||||
null,
|
||||
[],
|
||||
new DateRange(null, Chronos::parse($endDate)),
|
||||
];
|
||||
yield [
|
||||
['--startDate' => $startDate = '2019-01-01', '--endDate' => $endDate = '2020-05-23'],
|
||||
1,
|
||||
null,
|
||||
[],
|
||||
new DateRange(Chronos::parse($startDate), Chronos::parse($endDate)),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user