diff --git a/CHANGELOG.md b/CHANGELOG.md index ec85e5cc..307b510d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this * [#2018](https://github.com/shlinkio/shlink/issues/2018) Add option to allow all short URLs to be unconditionally crawlable in robots.txt, via `ROBOTS_ALLOW_ALL_SHORT_URLS=true` env var, or config option. * [#2109](https://github.com/shlinkio/shlink/issues/2109) Add option to customize user agents robots.txt, via `ROBOTS_USER_AGENTS=foo,bar,baz` env var, or config option. +* [#2163](https://github.com/shlinkio/shlink/issues/2163) Add `short-urls:edit` command to edit existing short URLs. + + This brings CLI and API interfaces capabilities closer, and solves an overlook since the feature was implemented years ago. ### Changed * [#2096](https://github.com/shlinkio/shlink/issues/2096) Update to RoadRunner 2024. diff --git a/module/CLI/test/Command/ShortUrl/EditShortUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/EditShortUrlCommandTest.php new file mode 100644 index 00000000..f540b5dc --- /dev/null +++ b/module/CLI/test/Command/ShortUrl/EditShortUrlCommandTest.php @@ -0,0 +1,74 @@ +shortUrlService = $this->createMock(ShortUrlServiceInterface::class); + $this->stringifier = $this->createMock(ShortUrlStringifierInterface::class); + + $command = new EditShortUrlCommand($this->shortUrlService, $this->stringifier); + $this->commandTester = CliTestUtils::testerForCommand($command); + } + + #[Test] + public function successMessageIsPrintedIfNoErrorOccurs(): void + { + $this->shortUrlService->expects($this->once())->method('updateShortUrl')->willReturn( + ShortUrl::createFake(), + ); + $this->stringifier->expects($this->once())->method('stringify')->willReturn('https://s.test/foo'); + + $this->commandTester->execute(['shortCode' => 'foobar']); + $output = $this->commandTester->getDisplay(); + $exitCode = $this->commandTester->getStatusCode(); + + self::assertStringContainsString('Short URL "https://s.test/foo" properly edited', $output); + self::assertEquals(ExitCode::EXIT_SUCCESS, $exitCode); + } + + #[Test] + #[TestWith([OutputInterface::VERBOSITY_NORMAL])] + #[TestWith([OutputInterface::VERBOSITY_VERBOSE])] + #[TestWith([OutputInterface::VERBOSITY_VERY_VERBOSE])] + #[TestWith([OutputInterface::VERBOSITY_DEBUG])] + public function errorIsPrintedInCaseOfFailure(int $verbosity): void + { + $e = ShortUrlNotFoundException::fromNotFound(ShortUrlIdentifier::fromShortCodeAndDomain('foo')); + $this->shortUrlService->expects($this->once())->method('updateShortUrl')->willThrowException($e); + $this->stringifier->expects($this->never())->method('stringify'); + + $this->commandTester->execute(['shortCode' => 'foo'], ['verbosity' => $verbosity]); + $output = $this->commandTester->getDisplay(); + $exitCode = $this->commandTester->getStatusCode(); + + self::assertStringContainsString('Short URL not found for "foo"', $output); + if ($verbosity >= OutputInterface::VERBOSITY_VERBOSE) { + self::assertStringContainsString('Exception trace:', $output); + } else { + self::assertStringNotContainsString('Exception trace:', $output); + } + self::assertEquals(ExitCode::EXIT_FAILURE, $exitCode); + } +}