Added searchTerm param to shortcode:list command

This commit is contained in:
Alejandro Celaya 2016-10-22 12:48:24 +02:00
parent 0a6030b35d
commit 8610a158d4
2 changed files with 23 additions and 10 deletions

View file

@ -56,6 +56,14 @@ class ListShortcodesCommand extends Command
), ),
1 1
) )
->addOption(
'searchTerm',
's',
InputOption::VALUE_OPTIONAL,
$this->translator->translate(
'A query used to filter results by searching for it on the longUrl and shortCode fields'
)
)
->addOption( ->addOption(
'tags', 'tags',
't', 't',
@ -67,13 +75,14 @@ class ListShortcodesCommand extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
$page = intval($input->getOption('page')); $page = intval($input->getOption('page'));
$searchTerm = $input->getOption('searchTerm');
$showTags = $input->getOption('tags'); $showTags = $input->getOption('tags');
/** @var QuestionHelper $helper */ /** @var QuestionHelper $helper */
$helper = $this->getHelper('question'); $helper = $this->getHelper('question');
do { do {
$result = $this->shortUrlService->listShortUrls($page); $result = $this->shortUrlService->listShortUrls($page, $searchTerm);
$page++; $page++;
$table = new Table($output); $table = new Table($output);

View file

@ -46,7 +46,7 @@ class ListShortcodesCommandTest extends TestCase
public function noInputCallsListJustOnce() public function noInputCallsListJustOnce()
{ {
$this->questionHelper->setInputStream($this->getInputStream('\n')); $this->questionHelper->setInputStream($this->getInputStream('\n'));
$this->shortUrlService->listShortUrls(1)->willReturn(new Paginator(new ArrayAdapter())) $this->shortUrlService->listShortUrls(1, null)->willReturn(new Paginator(new ArrayAdapter()))
->shouldBeCalledTimes(1); ->shouldBeCalledTimes(1);
$this->commandTester->execute(['command' => 'shortcode:list']); $this->commandTester->execute(['command' => 'shortcode:list']);
@ -66,7 +66,11 @@ class ListShortcodesCommandTest extends TestCase
$questionHelper = $this->questionHelper; $questionHelper = $this->questionHelper;
$that = $this; $that = $this;
$this->shortUrlService->listShortUrls(Argument::any())->will(function () use (&$data, $questionHelper, $that) { $this->shortUrlService->listShortUrls(Argument::cetera())->will(function () use (
&$data,
$questionHelper,
$that
) {
$questionHelper->setInputStream($that->getInputStream('y')); $questionHelper->setInputStream($that->getInputStream('y'));
return new Paginator(new ArrayAdapter(array_shift($data))); return new Paginator(new ArrayAdapter(array_shift($data)));
})->shouldBeCalledTimes(3); })->shouldBeCalledTimes(3);
@ -86,7 +90,7 @@ class ListShortcodesCommandTest extends TestCase
} }
$this->questionHelper->setInputStream($this->getInputStream('n')); $this->questionHelper->setInputStream($this->getInputStream('n'));
$this->shortUrlService->listShortUrls(Argument::any())->willReturn(new Paginator(new ArrayAdapter($data))) $this->shortUrlService->listShortUrls(Argument::cetera())->willReturn(new Paginator(new ArrayAdapter($data)))
->shouldBeCalledTimes(1); ->shouldBeCalledTimes(1);
$this->commandTester->execute(['command' => 'shortcode:list']); $this->commandTester->execute(['command' => 'shortcode:list']);
@ -99,7 +103,7 @@ class ListShortcodesCommandTest extends TestCase
{ {
$page = 5; $page = 5;
$this->questionHelper->setInputStream($this->getInputStream('\n')); $this->questionHelper->setInputStream($this->getInputStream('\n'));
$this->shortUrlService->listShortUrls($page)->willReturn(new Paginator(new ArrayAdapter())) $this->shortUrlService->listShortUrls($page, null)->willReturn(new Paginator(new ArrayAdapter()))
->shouldBeCalledTimes(1); ->shouldBeCalledTimes(1);
$this->commandTester->execute([ $this->commandTester->execute([
@ -114,7 +118,7 @@ class ListShortcodesCommandTest extends TestCase
public function ifTagsFlagIsProvidedTagsColumnIsIncluded() public function ifTagsFlagIsProvidedTagsColumnIsIncluded()
{ {
$this->questionHelper->setInputStream($this->getInputStream('\n')); $this->questionHelper->setInputStream($this->getInputStream('\n'));
$this->shortUrlService->listShortUrls(1)->willReturn(new Paginator(new ArrayAdapter())) $this->shortUrlService->listShortUrls(1, null)->willReturn(new Paginator(new ArrayAdapter()))
->shouldBeCalledTimes(1); ->shouldBeCalledTimes(1);
$this->commandTester->execute([ $this->commandTester->execute([