From 8610a158d4c7c1b45434f4b128b19153f2062238 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 22 Oct 2016 12:48:24 +0200 Subject: [PATCH] Added searchTerm param to shortcode:list command --- .../Shortcode/ListShortcodesCommand.php | 11 +++++++++- .../Shortcode/ListShortcodesCommandTest.php | 22 +++++++++++-------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/module/CLI/src/Command/Shortcode/ListShortcodesCommand.php b/module/CLI/src/Command/Shortcode/ListShortcodesCommand.php index a3f77903..b8a1310c 100644 --- a/module/CLI/src/Command/Shortcode/ListShortcodesCommand.php +++ b/module/CLI/src/Command/Shortcode/ListShortcodesCommand.php @@ -56,6 +56,14 @@ class ListShortcodesCommand extends Command ), 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( 'tags', 't', @@ -67,13 +75,14 @@ class ListShortcodesCommand extends Command public function execute(InputInterface $input, OutputInterface $output) { $page = intval($input->getOption('page')); + $searchTerm = $input->getOption('searchTerm'); $showTags = $input->getOption('tags'); /** @var QuestionHelper $helper */ $helper = $this->getHelper('question'); do { - $result = $this->shortUrlService->listShortUrls($page); + $result = $this->shortUrlService->listShortUrls($page, $searchTerm); $page++; $table = new Table($output); diff --git a/module/CLI/test/Command/Shortcode/ListShortcodesCommandTest.php b/module/CLI/test/Command/Shortcode/ListShortcodesCommandTest.php index a426eb06..8ab0d232 100644 --- a/module/CLI/test/Command/Shortcode/ListShortcodesCommandTest.php +++ b/module/CLI/test/Command/Shortcode/ListShortcodesCommandTest.php @@ -46,8 +46,8 @@ class ListShortcodesCommandTest extends TestCase public function noInputCallsListJustOnce() { $this->questionHelper->setInputStream($this->getInputStream('\n')); - $this->shortUrlService->listShortUrls(1)->willReturn(new Paginator(new ArrayAdapter())) - ->shouldBeCalledTimes(1); + $this->shortUrlService->listShortUrls(1, null)->willReturn(new Paginator(new ArrayAdapter())) + ->shouldBeCalledTimes(1); $this->commandTester->execute(['command' => 'shortcode:list']); } @@ -66,7 +66,11 @@ class ListShortcodesCommandTest extends TestCase $questionHelper = $this->questionHelper; $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')); return new Paginator(new ArrayAdapter(array_shift($data))); })->shouldBeCalledTimes(3); @@ -86,8 +90,8 @@ class ListShortcodesCommandTest extends TestCase } $this->questionHelper->setInputStream($this->getInputStream('n')); - $this->shortUrlService->listShortUrls(Argument::any())->willReturn(new Paginator(new ArrayAdapter($data))) - ->shouldBeCalledTimes(1); + $this->shortUrlService->listShortUrls(Argument::cetera())->willReturn(new Paginator(new ArrayAdapter($data))) + ->shouldBeCalledTimes(1); $this->commandTester->execute(['command' => 'shortcode:list']); } @@ -99,8 +103,8 @@ class ListShortcodesCommandTest extends TestCase { $page = 5; $this->questionHelper->setInputStream($this->getInputStream('\n')); - $this->shortUrlService->listShortUrls($page)->willReturn(new Paginator(new ArrayAdapter())) - ->shouldBeCalledTimes(1); + $this->shortUrlService->listShortUrls($page, null)->willReturn(new Paginator(new ArrayAdapter())) + ->shouldBeCalledTimes(1); $this->commandTester->execute([ 'command' => 'shortcode:list', @@ -114,8 +118,8 @@ class ListShortcodesCommandTest extends TestCase public function ifTagsFlagIsProvidedTagsColumnIsIncluded() { $this->questionHelper->setInputStream($this->getInputStream('\n')); - $this->shortUrlService->listShortUrls(1)->willReturn(new Paginator(new ArrayAdapter())) - ->shouldBeCalledTimes(1); + $this->shortUrlService->listShortUrls(1, null)->willReturn(new Paginator(new ArrayAdapter())) + ->shouldBeCalledTimes(1); $this->commandTester->execute([ 'command' => 'shortcode:list',