diff --git a/module/CLI/config/cli.config.php b/module/CLI/config/cli.config.php
index 14893d3d..bd7161c1 100644
--- a/module/CLI/config/cli.config.php
+++ b/module/CLI/config/cli.config.php
@@ -19,6 +19,7 @@ return [
Command\Api\ListKeysCommand::class,
Command\Tag\ListTagsCommand::class,
Command\Tag\CreateTagCommand::class,
+ Command\Tag\RenameTagCommand::class,
]
],
diff --git a/module/CLI/config/dependencies.config.php b/module/CLI/config/dependencies.config.php
index 11f0ce77..b02fa1c6 100644
--- a/module/CLI/config/dependencies.config.php
+++ b/module/CLI/config/dependencies.config.php
@@ -23,6 +23,7 @@ return [
Command\Api\ListKeysCommand::class => AnnotatedFactory::class,
Command\Tag\ListTagsCommand::class => AnnotatedFactory::class,
Command\Tag\CreateTagCommand::class => AnnotatedFactory::class,
+ Command\Tag\RenameTagCommand::class => AnnotatedFactory::class,
],
],
diff --git a/module/CLI/src/Command/Tag/CreateTagCommand.php b/module/CLI/src/Command/Tag/CreateTagCommand.php
index 97501847..8a06d38c 100644
--- a/module/CLI/src/Command/Tag/CreateTagCommand.php
+++ b/module/CLI/src/Command/Tag/CreateTagCommand.php
@@ -40,7 +40,7 @@ class CreateTagCommand extends Command
{
$this
->setName('tag:create')
- ->setDescription($this->translator->translate('Creates one or more tags'))
+ ->setDescription($this->translator->translate('Creates one or more tags.'))
->addOption(
'name',
't',
diff --git a/module/CLI/src/Command/Tag/ListTagsCommand.php b/module/CLI/src/Command/Tag/ListTagsCommand.php
index 3c781cb6..eb120226 100644
--- a/module/CLI/src/Command/Tag/ListTagsCommand.php
+++ b/module/CLI/src/Command/Tag/ListTagsCommand.php
@@ -41,7 +41,7 @@ class ListTagsCommand extends Command
{
$this
->setName('tag:list')
- ->setDescription($this->translator->translate('Lists existing tags'));
+ ->setDescription($this->translator->translate('Lists existing tags.'));
}
protected function execute(InputInterface $input, OutputInterface $output)
diff --git a/module/CLI/src/Command/Tag/RenameTagCommand.php b/module/CLI/src/Command/Tag/RenameTagCommand.php
new file mode 100644
index 00000000..7fd97b5e
--- /dev/null
+++ b/module/CLI/src/Command/Tag/RenameTagCommand.php
@@ -0,0 +1,65 @@
+tagService = $tagService;
+ $this->translator = $translator;
+ parent::__construct();
+ }
+
+ protected function configure()
+ {
+ $this
+ ->setName('tag:rename')
+ ->setDescription($this->translator->translate('Renames one existing tag.'))
+ ->addArgument('oldName', InputArgument::REQUIRED, $this->translator->translate('Current name of the tag.'))
+ ->addArgument('newName', InputArgument::REQUIRED, $this->translator->translate('New name of the tag.'));
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $oldName = $input->getArgument('oldName');
+ $newName = $input->getArgument('newName');
+
+ try {
+ $this->tagService->renameTag($oldName, $newName);
+ $output->writeln(sprintf('%s', $this->translator->translate('Tag properly renamed.')));
+ } catch (EntityDoesNotExistException $e) {
+ $output->writeln('' . sprintf($this->translator->translate(
+ 'A tag with name "%s" was not found'
+ ), $oldName) . '');
+ }
+ }
+}
diff --git a/module/CLI/test/Command/Tag/RenameTagCommandTest.php b/module/CLI/test/Command/Tag/RenameTagCommandTest.php
new file mode 100644
index 00000000..032bfcc7
--- /dev/null
+++ b/module/CLI/test/Command/Tag/RenameTagCommandTest.php
@@ -0,0 +1,82 @@
+tagService = $this->prophesize(TagServiceInterface::class);
+
+ $command = new RenameTagCommand($this->tagService->reveal(), Translator::factory([]));
+ $app = new Application();
+ $app->add($command);
+
+ $this->commandTester = new CommandTester($command);
+ }
+
+ /**
+ * @test
+ */
+ public function errorIsPrintedIfExceptionIsThrown()
+ {
+ $oldName = 'foo';
+ $newName = 'bar';
+ /** @var MethodProphecy $renameTag */
+ $renameTag = $this->tagService->renameTag($oldName, $newName)->willThrow(EntityDoesNotExistException::class);
+
+ $this->commandTester->execute([
+ 'oldName' => $oldName,
+ 'newName' => $newName,
+ ]);
+ $output = $this->commandTester->getDisplay();
+
+ $this->assertContains('A tag with name "foo" was not found', $output);
+ $renameTag->shouldHaveBeenCalled();
+ }
+
+ /**
+ * @test
+ */
+ public function successIsPrintedIfNoErrorOccurs()
+ {
+ $oldName = 'foo';
+ $newName = 'bar';
+ /** @var MethodProphecy $renameTag */
+ $renameTag = $this->tagService->renameTag($oldName, $newName)->willReturn(new Tag());
+
+ $this->commandTester->execute([
+ 'oldName' => $oldName,
+ 'newName' => $newName,
+ ]);
+ $output = $this->commandTester->getDisplay();
+
+ $this->assertContains('Tag properly renamed', $output);
+ $renameTag->shouldHaveBeenCalled();
+ }
+}