mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-22 15:13:59 -06:00
Added tests covering how orderBy is parsed on ListShortUrlsCommand
This commit is contained in:
parent
5616579131
commit
4b113e5781
@ -109,12 +109,12 @@ class ListShortUrlsCommand extends AbstractWithDateRangeCommand
|
||||
$showTags = (bool) $input->getOption('showTags');
|
||||
$startDate = $this->getDateOption($input, $output, 'startDate');
|
||||
$endDate = $this->getDateOption($input, $output, 'endDate');
|
||||
$orderBy = $this->processOrderBy($input);
|
||||
|
||||
$transformer = new ShortUrlDataTransformer($this->domainConfig);
|
||||
|
||||
do {
|
||||
$result = $this->renderPage(
|
||||
$input,
|
||||
$output,
|
||||
$page,
|
||||
$searchTerm,
|
||||
@ -122,6 +122,7 @@ class ListShortUrlsCommand extends AbstractWithDateRangeCommand
|
||||
$showTags,
|
||||
$startDate,
|
||||
$endDate,
|
||||
$orderBy,
|
||||
$transformer
|
||||
);
|
||||
$page++;
|
||||
@ -138,7 +139,6 @@ class ListShortUrlsCommand extends AbstractWithDateRangeCommand
|
||||
}
|
||||
|
||||
private function renderPage(
|
||||
InputInterface $input,
|
||||
OutputInterface $output,
|
||||
int $page,
|
||||
?string $searchTerm,
|
||||
@ -146,13 +146,14 @@ class ListShortUrlsCommand extends AbstractWithDateRangeCommand
|
||||
bool $showTags,
|
||||
?Chronos $startDate,
|
||||
?Chronos $endDate,
|
||||
$orderBy,
|
||||
DataTransformerInterface $transformer
|
||||
): Paginator {
|
||||
$result = $this->shortUrlService->listShortUrls(
|
||||
$page,
|
||||
$searchTerm,
|
||||
$tags,
|
||||
$this->processOrderBy($input),
|
||||
$orderBy,
|
||||
new DateRange($startDate, $endDate)
|
||||
);
|
||||
|
||||
@ -181,6 +182,9 @@ class ListShortUrlsCommand extends AbstractWithDateRangeCommand
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|string|null
|
||||
*/
|
||||
private function processOrderBy(InputInterface $input)
|
||||
{
|
||||
$orderBy = $input->getOption('orderBy');
|
||||
|
@ -162,4 +162,27 @@ class ListShortUrlsCommandTest extends TestCase
|
||||
new DateRange(Chronos::parse($startDate), Chronos::parse($endDate)),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideOrderBy
|
||||
*/
|
||||
public function orderByIsProperlyComputed(array $commandArgs, $expectedOrderBy): void
|
||||
{
|
||||
$listShortUrls = $this->shortUrlService->listShortUrls(1, null, [], $expectedOrderBy, new DateRange())
|
||||
->willReturn(new Paginator(new ArrayAdapter()));
|
||||
|
||||
$this->commandTester->setInputs(['n']);
|
||||
$this->commandTester->execute($commandArgs);
|
||||
|
||||
$listShortUrls->shouldHaveBeenCalledOnce();
|
||||
}
|
||||
|
||||
public function provideOrderBy(): iterable
|
||||
{
|
||||
yield [[], null];
|
||||
yield [['--orderBy' => 'foo'], 'foo'];
|
||||
yield [['--orderBy' => 'foo,ASC'], ['foo' => 'ASC']];
|
||||
yield [['--orderBy' => 'bar,DESC'], ['bar' => 'DESC']];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user