From a138f4153dae260de5520dccc28737f9f3d82045 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 16 Jul 2017 09:35:24 +0200 Subject: [PATCH] Created DeleteTagsCommand --- module/CLI/config/cli.config.php | 1 + module/CLI/config/dependencies.config.php | 1 + .../CLI/src/Command/Tag/DeleteTagsCommand.php | 69 +++++++++++++++++++ .../Command/Tag/DeleteTagsCommandTest.php | 68 ++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 module/CLI/src/Command/Tag/DeleteTagsCommand.php create mode 100644 module/CLI/test/Command/Tag/DeleteTagsCommandTest.php diff --git a/module/CLI/config/cli.config.php b/module/CLI/config/cli.config.php index a7a4fb9b..a1a34c16 100644 --- a/module/CLI/config/cli.config.php +++ b/module/CLI/config/cli.config.php @@ -21,6 +21,7 @@ return [ Command\Tag\ListTagsCommand::class, Command\Tag\CreateTagCommand::class, Command\Tag\RenameTagCommand::class, + Command\Tag\DeleteTagsCommand::class, ] ], diff --git a/module/CLI/config/dependencies.config.php b/module/CLI/config/dependencies.config.php index b02fa1c6..565ab8bc 100644 --- a/module/CLI/config/dependencies.config.php +++ b/module/CLI/config/dependencies.config.php @@ -24,6 +24,7 @@ return [ Command\Tag\ListTagsCommand::class => AnnotatedFactory::class, Command\Tag\CreateTagCommand::class => AnnotatedFactory::class, Command\Tag\RenameTagCommand::class => AnnotatedFactory::class, + Command\Tag\DeleteTagsCommand::class => AnnotatedFactory::class, ], ], diff --git a/module/CLI/src/Command/Tag/DeleteTagsCommand.php b/module/CLI/src/Command/Tag/DeleteTagsCommand.php new file mode 100644 index 00000000..0a4e271b --- /dev/null +++ b/module/CLI/src/Command/Tag/DeleteTagsCommand.php @@ -0,0 +1,69 @@ +tagService = $tagService; + $this->translator = $translator; + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('tag:delete') + ->setDescription($this->translator->translate('Deletes one or more tags.')) + ->addOption( + 'name', + 't', + InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, + $this->translator->translate('The name of the tags to delete') + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $tagNames = $input->getOption('name'); + if (empty($tagNames)) { + $output->writeln(sprintf( + '%s', + $this->translator->translate('You have to provide at least one tag name') + )); + return; + } + + $this->tagService->deleteTags($tagNames); + $output->writeln($this->translator->translate('Deleted tags') . sprintf(': ["%s"]', implode( + '", "', + $tagNames + ))); + } +} diff --git a/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php b/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php new file mode 100644 index 00000000..9498a450 --- /dev/null +++ b/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php @@ -0,0 +1,68 @@ +tagService = $this->prophesize(TagServiceInterface::class); + + $command = new DeleteTagsCommand($this->tagService->reveal(), Translator::factory([])); + $app = new Application(); + $app->add($command); + + $this->commandTester = new CommandTester($command); + } + + /** + * @test + */ + public function errorIsReturnedWhenNoTagsAreProvided() + { + $this->commandTester->execute([]); + + $output = $this->commandTester->getDisplay(); + $this->assertContains('You have to provide at least one tag name', $output); + } + + /** + * @test + */ + public function serviceIsInvokedOnSuccess() + { + $tagNames = ['foo', 'bar']; + /** @var MethodProphecy $deleteTags */ + $deleteTags = $this->tagService->deleteTags($tagNames)->will(function () { + }); + + $this->commandTester->execute([ + '--name' => $tagNames, + ]); + $output = $this->commandTester->getDisplay(); + + $this->assertContains(sprintf('Deleted tags: ["%s"]', implode('", "', $tagNames)), $output); + $deleteTags->shouldHaveBeenCalled(); + } +}