diff --git a/module/CLI/src/Command/Api/DisableKeyCommand.php b/module/CLI/src/Command/Api/DisableKeyCommand.php index 93178bb5..52169b26 100644 --- a/module/CLI/src/Command/Api/DisableKeyCommand.php +++ b/module/CLI/src/Command/Api/DisableKeyCommand.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\Api; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Common\Exception\InvalidArgumentException; use Shlinkio\Shlink\Rest\Entity\ApiKey; use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; @@ -89,7 +88,7 @@ class DisableKeyCommand extends Command if (! $keyOrName) { $io->warning('An API key name was not provided.'); - return ExitCode::EXIT_WARNING; + return Command::INVALID; } try { @@ -99,10 +98,10 @@ class DisableKeyCommand extends Command $this->apiKeyService->disableByKey($keyOrName); } $io->success(sprintf('API key "%s" properly disabled', $keyOrName)); - return ExitCode::EXIT_SUCCESS; + return Command::SUCCESS; } catch (InvalidArgumentException $e) { $io->error($e->getMessage()); - return ExitCode::EXIT_FAILURE; + return Command::FAILURE; } } } diff --git a/module/CLI/src/Command/Api/GenerateKeyCommand.php b/module/CLI/src/Command/Api/GenerateKeyCommand.php index 2790fa8c..0c4afcd0 100644 --- a/module/CLI/src/Command/Api/GenerateKeyCommand.php +++ b/module/CLI/src/Command/Api/GenerateKeyCommand.php @@ -6,7 +6,6 @@ namespace Shlinkio\Shlink\CLI\Command\Api; use Cake\Chronos\Chronos; use Shlinkio\Shlink\CLI\ApiKey\RoleResolverInterface; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\CLI\Util\ShlinkTable; use Shlinkio\Shlink\Rest\ApiKey\Model\ApiKeyMeta; use Shlinkio\Shlink\Rest\ApiKey\Role; @@ -123,6 +122,6 @@ class GenerateKeyCommand extends Command ); } - return ExitCode::EXIT_SUCCESS; + return Command::SUCCESS; } } diff --git a/module/CLI/src/Command/Api/InitialApiKeyCommand.php b/module/CLI/src/Command/Api/InitialApiKeyCommand.php index e6515bc3..66968eb3 100644 --- a/module/CLI/src/Command/Api/InitialApiKeyCommand.php +++ b/module/CLI/src/Command/Api/InitialApiKeyCommand.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\Api; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -38,6 +37,6 @@ class InitialApiKeyCommand extends Command $output->writeln('Other API keys already exist. Initial API key creation skipped.'); } - return ExitCode::EXIT_SUCCESS; + return Command::SUCCESS; } } diff --git a/module/CLI/src/Command/Api/ListKeysCommand.php b/module/CLI/src/Command/Api/ListKeysCommand.php index 69870a9b..7d63b6a4 100644 --- a/module/CLI/src/Command/Api/ListKeysCommand.php +++ b/module/CLI/src/Command/Api/ListKeysCommand.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\Api; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\CLI\Util\ShlinkTable; use Shlinkio\Shlink\Rest\ApiKey\Role; use Shlinkio\Shlink\Rest\Entity\ApiKey; @@ -73,7 +72,7 @@ class ListKeysCommand extends Command 'Roles', ]), $rows); - return ExitCode::EXIT_SUCCESS; + return Command::SUCCESS; } private function determineMessagePattern(ApiKey $apiKey): string diff --git a/module/CLI/src/Command/Api/RenameApiKeyCommand.php b/module/CLI/src/Command/Api/RenameApiKeyCommand.php index eb662539..f21d125b 100644 --- a/module/CLI/src/Command/Api/RenameApiKeyCommand.php +++ b/module/CLI/src/Command/Api/RenameApiKeyCommand.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\Api; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Exception\InvalidArgumentException; use Shlinkio\Shlink\Core\Model\Renaming; use Shlinkio\Shlink\Rest\Entity\ApiKey; @@ -72,6 +71,6 @@ class RenameApiKeyCommand extends Command $this->apiKeyService->renameApiKey(Renaming::fromNames($oldName, $newName)); $io->success('API key properly renamed'); - return ExitCode::EXIT_SUCCESS; + return Command::SUCCESS; } } diff --git a/module/CLI/src/Command/Config/ReadEnvVarCommand.php b/module/CLI/src/Command/Config/ReadEnvVarCommand.php index 72e07f97..e1cef3fd 100644 --- a/module/CLI/src/Command/Config/ReadEnvVarCommand.php +++ b/module/CLI/src/Command/Config/ReadEnvVarCommand.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\Config; use Closure; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Config\EnvVars; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Exception\InvalidArgumentException; @@ -63,6 +62,6 @@ class ReadEnvVarCommand extends Command $envVar = $input->getArgument('envVar'); $output->writeln(formatEnvVarValue(($this->loadEnvVar)($envVar))); - return ExitCode::EXIT_SUCCESS; + return Command::SUCCESS; } } diff --git a/module/CLI/src/Command/Db/CreateDatabaseCommand.php b/module/CLI/src/Command/Db/CreateDatabaseCommand.php index b2a2fa18..6dc11dfc 100644 --- a/module/CLI/src/Command/Db/CreateDatabaseCommand.php +++ b/module/CLI/src/Command/Db/CreateDatabaseCommand.php @@ -7,7 +7,6 @@ namespace Shlinkio\Shlink\CLI\Command\Db; use Doctrine\DBAL\Connection; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\CLI\Util\ProcessRunnerInterface; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -55,7 +54,7 @@ class CreateDatabaseCommand extends AbstractDatabaseCommand if ($this->databaseTablesExist()) { $io->success('Database already exists. Run "db:migrate" command to make sure it is up to date.'); - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } // Create database @@ -63,7 +62,7 @@ class CreateDatabaseCommand extends AbstractDatabaseCommand $this->runPhpCommand($output, [self::DOCTRINE_SCRIPT, self::DOCTRINE_CREATE_SCHEMA_COMMAND]); $io->success('Database properly created!'); - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } private function databaseTablesExist(): bool diff --git a/module/CLI/src/Command/Db/MigrateDatabaseCommand.php b/module/CLI/src/Command/Db/MigrateDatabaseCommand.php index 2e280a06..669b190b 100644 --- a/module/CLI/src/Command/Db/MigrateDatabaseCommand.php +++ b/module/CLI/src/Command/Db/MigrateDatabaseCommand.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\Db; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; @@ -31,6 +30,6 @@ class MigrateDatabaseCommand extends AbstractDatabaseCommand $this->runPhpCommand($output, [self::DOCTRINE_MIGRATIONS_SCRIPT, self::DOCTRINE_MIGRATE_COMMAND]); $io->success('Database properly migrated!'); - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } } diff --git a/module/CLI/src/Command/Domain/DomainRedirectsCommand.php b/module/CLI/src/Command/Domain/DomainRedirectsCommand.php index 105c10e3..4c2e4350 100644 --- a/module/CLI/src/Command/Domain/DomainRedirectsCommand.php +++ b/module/CLI/src/Command/Domain/DomainRedirectsCommand.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\Domain; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Config\NotFoundRedirects; use Shlinkio\Shlink\Core\Domain\DomainServiceInterface; use Shlinkio\Shlink\Core\Domain\Model\DomainItem; @@ -109,6 +108,6 @@ class DomainRedirectsCommand extends Command $io->success(sprintf('"Not found" redirects properly set for "%s"', $domainAuthority)); - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } } diff --git a/module/CLI/src/Command/Domain/ListDomainsCommand.php b/module/CLI/src/Command/Domain/ListDomainsCommand.php index 79c181f7..935d272e 100644 --- a/module/CLI/src/Command/Domain/ListDomainsCommand.php +++ b/module/CLI/src/Command/Domain/ListDomainsCommand.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\Domain; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\CLI\Util\ShlinkTable; use Shlinkio\Shlink\Core\Config\NotFoundRedirectConfigInterface; use Shlinkio\Shlink\Core\Domain\DomainServiceInterface; @@ -59,7 +58,7 @@ class ListDomainsCommand extends Command }, $domains), ); - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } private function notFoundRedirectsToString(NotFoundRedirectConfigInterface $config): string diff --git a/module/CLI/src/Command/Integration/MatomoSendVisitsCommand.php b/module/CLI/src/Command/Integration/MatomoSendVisitsCommand.php index 9a41cc05..c1c22075 100644 --- a/module/CLI/src/Command/Integration/MatomoSendVisitsCommand.php +++ b/module/CLI/src/Command/Integration/MatomoSendVisitsCommand.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\Integration; use Cake\Chronos\Chronos; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Matomo\MatomoOptions; use Shlinkio\Shlink\Core\Matomo\MatomoVisitSenderInterface; use Shlinkio\Shlink\Core\Matomo\VisitSendingProgressTrackerInterface; @@ -84,7 +83,7 @@ class MatomoSendVisitsCommand extends Command implements VisitSendingProgressTra if (! $this->matomoEnabled) { $this->io->warning('Matomo integration is not enabled in this Shlink instance'); - return ExitCode::EXIT_WARNING; + return self::INVALID; } // TODO Validate provided date formats @@ -103,7 +102,7 @@ class MatomoSendVisitsCommand extends Command implements VisitSendingProgressTra . 'you have verified only visits in the right date range are going to be sent.', ]); if (! $this->io->confirm('Continue?', default: false)) { - return ExitCode::EXIT_WARNING; + return self::INVALID; } } @@ -122,7 +121,7 @@ class MatomoSendVisitsCommand extends Command implements VisitSendingProgressTra default => $this->io->info('There was no visits matching provided date range.'), }; - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } public function success(int $index): void diff --git a/module/CLI/src/Command/RedirectRule/ManageRedirectRulesCommand.php b/module/CLI/src/Command/RedirectRule/ManageRedirectRulesCommand.php index 646b9d77..9a129e9d 100644 --- a/module/CLI/src/Command/RedirectRule/ManageRedirectRulesCommand.php +++ b/module/CLI/src/Command/RedirectRule/ManageRedirectRulesCommand.php @@ -6,7 +6,6 @@ namespace Shlinkio\Shlink\CLI\Command\RedirectRule; use Shlinkio\Shlink\CLI\Input\ShortUrlIdentifierInput; use Shlinkio\Shlink\CLI\RedirectRule\RedirectRuleHandlerInterface; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; use Shlinkio\Shlink\Core\RedirectRule\ShortUrlRedirectRuleServiceInterface; use Shlinkio\Shlink\Core\ShortUrl\ShortUrlResolverInterface; @@ -52,7 +51,7 @@ class ManageRedirectRulesCommand extends Command $shortUrl = $this->shortUrlResolver->resolveShortUrl($identifier); } catch (ShortUrlNotFoundException) { $io->error(sprintf('Short URL for %s not found', $identifier->__toString())); - return ExitCode::EXIT_FAILURE; + return self::FAILURE; } $rulesToSave = $this->ruleHandler->manageRules($io, $shortUrl, $this->ruleService->rulesForShortUrl($shortUrl)); @@ -61,6 +60,6 @@ class ManageRedirectRulesCommand extends Command $io->success('Rules properly saved'); } - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } } diff --git a/module/CLI/src/Command/ShortUrl/CreateShortUrlCommand.php b/module/CLI/src/Command/ShortUrl/CreateShortUrlCommand.php index df341c96..2e52571b 100644 --- a/module/CLI/src/Command/ShortUrl/CreateShortUrlCommand.php +++ b/module/CLI/src/Command/ShortUrl/CreateShortUrlCommand.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\ShortUrl; use Shlinkio\Shlink\CLI\Input\ShortUrlDataInput; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\Exception\NonUniqueSlugException; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifierInterface; @@ -114,10 +113,10 @@ class CreateShortUrlCommand extends Command sprintf('Processed long URL: %s', $result->shortUrl->getLongUrl()), sprintf('Generated short URL: %s', $this->stringifier->stringify($result->shortUrl)), ]); - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } catch (NonUniqueSlugException $e) { $io->error($e->getMessage()); - return ExitCode::EXIT_FAILURE; + return self::FAILURE; } } diff --git a/module/CLI/src/Command/ShortUrl/DeleteExpiredShortUrlsCommand.php b/module/CLI/src/Command/ShortUrl/DeleteExpiredShortUrlsCommand.php index 1fc9dc38..2b2abd01 100644 --- a/module/CLI/src/Command/ShortUrl/DeleteExpiredShortUrlsCommand.php +++ b/module/CLI/src/Command/ShortUrl/DeleteExpiredShortUrlsCommand.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\ShortUrl; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\ShortUrl\DeleteShortUrlServiceInterface; use Shlinkio\Shlink\Core\ShortUrl\Model\ExpiredShortUrlsConditions; use Symfony\Component\Console\Command\Command; @@ -58,18 +57,18 @@ class DeleteExpiredShortUrlsCommand extends Command 'This action cannot be undone. Proceed at your own risk', ]); if (! $io->confirm('Continue?', default: false)) { - return ExitCode::EXIT_WARNING; + return self::INVALID; } } if ($dryRun) { $result = $this->deleteShortUrlService->countExpiredShortUrls($conditions); $io->success(sprintf('There are %s expired short URLs matching provided conditions', $result)); - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } $result = $this->deleteShortUrlService->deleteExpiredShortUrls($conditions); $io->success(sprintf('%s expired short URLs have been deleted', $result)); - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } } diff --git a/module/CLI/src/Command/ShortUrl/DeleteShortUrlCommand.php b/module/CLI/src/Command/ShortUrl/DeleteShortUrlCommand.php index edda1b29..e6a11ea1 100644 --- a/module/CLI/src/Command/ShortUrl/DeleteShortUrlCommand.php +++ b/module/CLI/src/Command/ShortUrl/DeleteShortUrlCommand.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\ShortUrl; use Shlinkio\Shlink\CLI\Input\ShortUrlIdentifierInput; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Exception; use Shlinkio\Shlink\Core\ShortUrl\DeleteShortUrlServiceInterface; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier; @@ -55,10 +54,10 @@ class DeleteShortUrlCommand extends Command try { $this->runDelete($io, $identifier, $ignoreThreshold); - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } catch (Exception\ShortUrlNotFoundException $e) { $io->error($e->getMessage()); - return ExitCode::EXIT_FAILURE; + return self::FAILURE; } catch (Exception\DeleteShortUrlException $e) { return $this->retry($io, $identifier, $e->getMessage()); } @@ -75,7 +74,7 @@ class DeleteShortUrlCommand extends Command $io->warning('Short URL was not deleted.'); } - return $forceDelete ? ExitCode::EXIT_SUCCESS : ExitCode::EXIT_WARNING; + return $forceDelete ? self::SUCCESS : self::INVALID; } private function runDelete(SymfonyStyle $io, ShortUrlIdentifier $identifier, bool $ignoreThreshold): void diff --git a/module/CLI/src/Command/ShortUrl/DeleteShortUrlVisitsCommand.php b/module/CLI/src/Command/ShortUrl/DeleteShortUrlVisitsCommand.php index a9a709a1..4c238f31 100644 --- a/module/CLI/src/Command/ShortUrl/DeleteShortUrlVisitsCommand.php +++ b/module/CLI/src/Command/ShortUrl/DeleteShortUrlVisitsCommand.php @@ -6,7 +6,6 @@ namespace Shlinkio\Shlink\CLI\Command\ShortUrl; use Shlinkio\Shlink\CLI\Command\Visit\AbstractDeleteVisitsCommand; use Shlinkio\Shlink\CLI\Input\ShortUrlIdentifierInput; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; use Shlinkio\Shlink\Core\ShortUrl\ShortUrlVisitsDeleterInterface; use Symfony\Component\Console\Input\InputInterface; @@ -44,10 +43,10 @@ class DeleteShortUrlVisitsCommand extends AbstractDeleteVisitsCommand $result = $this->deleter->deleteShortUrlVisits($identifier); $io->success(sprintf('Successfully deleted %s visits', $result->affectedItems)); - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } catch (ShortUrlNotFoundException) { $io->warning(sprintf('Short URL not found for "%s"', $identifier->__toString())); - return ExitCode::EXIT_WARNING; + return self::INVALID; } } diff --git a/module/CLI/src/Command/ShortUrl/EditShortUrlCommand.php b/module/CLI/src/Command/ShortUrl/EditShortUrlCommand.php index ad9aaf70..16fe9458 100644 --- a/module/CLI/src/Command/ShortUrl/EditShortUrlCommand.php +++ b/module/CLI/src/Command/ShortUrl/EditShortUrlCommand.php @@ -6,7 +6,6 @@ namespace Shlinkio\Shlink\CLI\Command\ShortUrl; use Shlinkio\Shlink\CLI\Input\ShortUrlDataInput; use Shlinkio\Shlink\CLI\Input\ShortUrlIdentifierInput; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifierInterface; use Shlinkio\Shlink\Core\ShortUrl\ShortUrlServiceInterface; @@ -57,7 +56,7 @@ class EditShortUrlCommand extends Command ); $io->success(sprintf('Short URL "%s" properly edited', $this->stringifier->stringify($shortUrl))); - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } catch (ShortUrlNotFoundException $e) { $io->error(sprintf('Short URL not found for "%s"', $identifier->__toString())); @@ -65,7 +64,7 @@ class EditShortUrlCommand extends Command $this->getApplication()?->renderThrowable($e, $io); } - return ExitCode::EXIT_FAILURE; + return self::FAILURE; } } } diff --git a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php index 72222a08..5bdc4c81 100644 --- a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php +++ b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php @@ -6,7 +6,6 @@ namespace Shlinkio\Shlink\CLI\Command\ShortUrl; use Shlinkio\Shlink\CLI\Input\EndDateOption; use Shlinkio\Shlink\CLI\Input\StartDateOption; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\CLI\Util\ShlinkTable; use Shlinkio\Shlink\Common\Paginator\Paginator; use Shlinkio\Shlink\Common\Paginator\Util\PagerfantaUtils; @@ -176,7 +175,7 @@ class ListShortUrlsCommand extends Command $io->newLine(); $io->success('Short URLs properly listed'); - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } /** diff --git a/module/CLI/src/Command/ShortUrl/ResolveUrlCommand.php b/module/CLI/src/Command/ShortUrl/ResolveUrlCommand.php index 7935df6d..b6bf71f7 100644 --- a/module/CLI/src/Command/ShortUrl/ResolveUrlCommand.php +++ b/module/CLI/src/Command/ShortUrl/ResolveUrlCommand.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\ShortUrl; use Shlinkio\Shlink\CLI\Input\ShortUrlIdentifierInput; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; use Shlinkio\Shlink\Core\ShortUrl\ShortUrlResolverInterface; use Symfony\Component\Console\Command\Command; @@ -59,10 +58,10 @@ class ResolveUrlCommand extends Command try { $url = $this->urlResolver->resolveShortUrl($this->shortUrlIdentifierInput->toShortUrlIdentifier($input)); $output->writeln(sprintf('Long URL: %s', $url->getLongUrl())); - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } catch (ShortUrlNotFoundException $e) { $io->error($e->getMessage()); - return ExitCode::EXIT_FAILURE; + return self::FAILURE; } } } diff --git a/module/CLI/src/Command/Tag/DeleteTagsCommand.php b/module/CLI/src/Command/Tag/DeleteTagsCommand.php index 2f13e775..2022a9dc 100644 --- a/module/CLI/src/Command/Tag/DeleteTagsCommand.php +++ b/module/CLI/src/Command/Tag/DeleteTagsCommand.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\Tag; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Tag\TagServiceInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -41,11 +40,11 @@ class DeleteTagsCommand extends Command if (empty($tagNames)) { $io->warning('You have to provide at least one tag name'); - return ExitCode::EXIT_WARNING; + return self::INVALID; } $this->tagService->deleteTags($tagNames); $io->success('Tags properly deleted'); - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } } diff --git a/module/CLI/src/Command/Tag/ListTagsCommand.php b/module/CLI/src/Command/Tag/ListTagsCommand.php index 8333b82e..abd9a0dd 100644 --- a/module/CLI/src/Command/Tag/ListTagsCommand.php +++ b/module/CLI/src/Command/Tag/ListTagsCommand.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\Tag; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\CLI\Util\ShlinkTable; use Shlinkio\Shlink\Core\Tag\Model\TagInfo; use Shlinkio\Shlink\Core\Tag\Model\TagsParams; @@ -34,7 +33,7 @@ class ListTagsCommand extends Command protected function execute(InputInterface $input, OutputInterface $output): int { ShlinkTable::default($output)->render(['Name', 'URLs amount', 'Visits amount'], $this->getTagsRows()); - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } private function getTagsRows(): array diff --git a/module/CLI/src/Command/Tag/RenameTagCommand.php b/module/CLI/src/Command/Tag/RenameTagCommand.php index 42092d04..2ae0159c 100644 --- a/module/CLI/src/Command/Tag/RenameTagCommand.php +++ b/module/CLI/src/Command/Tag/RenameTagCommand.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\Tag; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Exception\TagConflictException; use Shlinkio\Shlink\Core\Exception\TagNotFoundException; use Shlinkio\Shlink\Core\Model\Renaming; @@ -42,10 +41,10 @@ class RenameTagCommand extends Command try { $this->tagService->renameTag(Renaming::fromNames($oldName, $newName)); $io->success('Tag properly renamed.'); - return ExitCode::EXIT_SUCCESS; + return Command::SUCCESS; } catch (TagNotFoundException | TagConflictException $e) { $io->error($e->getMessage()); - return ExitCode::EXIT_FAILURE; + return Command::FAILURE; } } } diff --git a/module/CLI/src/Command/Util/AbstractLockedCommand.php b/module/CLI/src/Command/Util/AbstractLockedCommand.php index 8bd728cd..a4c3ef5d 100644 --- a/module/CLI/src/Command/Util/AbstractLockedCommand.php +++ b/module/CLI/src/Command/Util/AbstractLockedCommand.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\Util; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -28,7 +27,7 @@ abstract class AbstractLockedCommand extends Command $output->writeln( sprintf('Command "%s" is already in progress. Skipping.', $lockConfig->lockName), ); - return ExitCode::EXIT_WARNING; + return self::INVALID; } try { diff --git a/module/CLI/src/Command/Visit/AbstractDeleteVisitsCommand.php b/module/CLI/src/Command/Visit/AbstractDeleteVisitsCommand.php index 7cb32698..d8ef98e3 100644 --- a/module/CLI/src/Command/Visit/AbstractDeleteVisitsCommand.php +++ b/module/CLI/src/Command/Visit/AbstractDeleteVisitsCommand.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\Visit; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -17,7 +16,7 @@ abstract class AbstractDeleteVisitsCommand extends Command $io = new SymfonyStyle($input, $output); if (! $this->confirm($io)) { $io->info('Operation aborted'); - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } return $this->doExecute($input, $io); diff --git a/module/CLI/src/Command/Visit/AbstractVisitsListCommand.php b/module/CLI/src/Command/Visit/AbstractVisitsListCommand.php index b95c6845..5916fc52 100644 --- a/module/CLI/src/Command/Visit/AbstractVisitsListCommand.php +++ b/module/CLI/src/Command/Visit/AbstractVisitsListCommand.php @@ -6,7 +6,6 @@ namespace Shlinkio\Shlink\CLI\Command\Visit; use Shlinkio\Shlink\CLI\Input\EndDateOption; use Shlinkio\Shlink\CLI\Input\StartDateOption; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\CLI\Util\ShlinkTable; use Shlinkio\Shlink\Common\Paginator\Paginator; use Shlinkio\Shlink\Common\Util\DateRange; @@ -43,7 +42,7 @@ abstract class AbstractVisitsListCommand extends Command ShlinkTable::default($output)->render($headers, $rows); - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } /** diff --git a/module/CLI/src/Command/Visit/DeleteOrphanVisitsCommand.php b/module/CLI/src/Command/Visit/DeleteOrphanVisitsCommand.php index 056a9c60..77fefaaa 100644 --- a/module/CLI/src/Command/Visit/DeleteOrphanVisitsCommand.php +++ b/module/CLI/src/Command/Visit/DeleteOrphanVisitsCommand.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\Visit; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Visit\VisitsDeleterInterface; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Style\SymfonyStyle; @@ -32,7 +31,7 @@ class DeleteOrphanVisitsCommand extends AbstractDeleteVisitsCommand $result = $this->deleter->deleteOrphanVisits(); $io->success(sprintf('Successfully deleted %s visits', $result->affectedItems)); - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } protected function getWarningMessage(): string diff --git a/module/CLI/src/Command/Visit/DownloadGeoLiteDbCommand.php b/module/CLI/src/Command/Visit/DownloadGeoLiteDbCommand.php index cd7c4ffb..4d58a7d3 100644 --- a/module/CLI/src/Command/Visit/DownloadGeoLiteDbCommand.php +++ b/module/CLI/src/Command/Visit/DownloadGeoLiteDbCommand.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shlinkio\Shlink\CLI\Command\Visit; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Exception\GeolocationDbUpdateFailedException; use Shlinkio\Shlink\Core\Geolocation\GeolocationDbUpdaterInterface; use Shlinkio\Shlink\Core\Geolocation\GeolocationDownloadProgressHandlerInterface; @@ -48,17 +47,17 @@ class DownloadGeoLiteDbCommand extends Command implements GeolocationDownloadPro if ($result === GeolocationResult::LICENSE_MISSING) { $this->io->warning('It was not possible to download GeoLite2 db, because a license was not provided.'); - return ExitCode::EXIT_WARNING; + return self::INVALID; } if ($result === GeolocationResult::MAX_ERRORS_REACHED) { $this->io->warning('Max consecutive errors reached. Cannot retry for a couple of days.'); - return ExitCode::EXIT_WARNING; + return self::INVALID; } if ($result === GeolocationResult::UPDATE_IN_PROGRESS) { $this->io->warning('A geolocation db is already being downloaded by another process.'); - return ExitCode::EXIT_WARNING; + return self::INVALID; } if ($this->progressBar === null) { @@ -68,7 +67,7 @@ class DownloadGeoLiteDbCommand extends Command implements GeolocationDownloadPro $this->io->success('GeoLite2 db file properly downloaded.'); } - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } catch (GeolocationDbUpdateFailedException $e) { return $this->processGeoLiteUpdateError($e, $this->io); } @@ -90,7 +89,7 @@ class DownloadGeoLiteDbCommand extends Command implements GeolocationDownloadPro $this->getApplication()?->renderThrowable($e, $io); } - return $olderDbExists ? ExitCode::EXIT_WARNING : ExitCode::EXIT_FAILURE; + return $olderDbExists ? self::INVALID : self::FAILURE; } public function beforeDownload(bool $olderDbExists): void diff --git a/module/CLI/src/Command/Visit/LocateVisitsCommand.php b/module/CLI/src/Command/Visit/LocateVisitsCommand.php index 66e33a78..3ed2edf9 100644 --- a/module/CLI/src/Command/Visit/LocateVisitsCommand.php +++ b/module/CLI/src/Command/Visit/LocateVisitsCommand.php @@ -6,7 +6,6 @@ namespace Shlinkio\Shlink\CLI\Command\Visit; use Shlinkio\Shlink\CLI\Command\Util\AbstractLockedCommand; use Shlinkio\Shlink\CLI\Command\Util\LockedCommandConfig; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Common\Util\IpAddress; use Shlinkio\Shlink\Core\Exception\IpCannotBeLocatedException; use Shlinkio\Shlink\Core\Visit\Entity\Visit; @@ -116,14 +115,14 @@ class LocateVisitsCommand extends AbstractLockedCommand implements VisitGeolocat } $this->io->success('Finished locating visits'); - return ExitCode::EXIT_SUCCESS; + return self::SUCCESS; } catch (Throwable $e) { $this->io->error($e->getMessage()); if ($this->io->isVerbose()) { $this->getApplication()?->renderThrowable($e, $this->io); } - return ExitCode::EXIT_FAILURE; + return self::FAILURE; } } @@ -171,7 +170,7 @@ class LocateVisitsCommand extends AbstractLockedCommand implements VisitGeolocat $downloadDbCommand = $cliApp->find(DownloadGeoLiteDbCommand::NAME); $exitCode = $downloadDbCommand->run(new ArrayInput([]), $this->io); - if ($exitCode === ExitCode::EXIT_FAILURE) { + if ($exitCode === self::FAILURE) { throw new RuntimeException('It is not possible to locate visits without a GeoLite2 db file.'); } } diff --git a/module/CLI/src/Util/ExitCode.php b/module/CLI/src/Util/ExitCode.php deleted file mode 100644 index f2ffa16b..00000000 --- a/module/CLI/src/Util/ExitCode.php +++ /dev/null @@ -1,12 +0,0 @@ -exec([ListShortUrlsCommand::NAME, '--show-domain', '--search-term', $slug]); diff --git a/module/CLI/test-cli/Command/GenerateApiKeyTest.php b/module/CLI/test-cli/Command/GenerateApiKeyTest.php index 7d90c336..a8479ecf 100644 --- a/module/CLI/test-cli/Command/GenerateApiKeyTest.php +++ b/module/CLI/test-cli/Command/GenerateApiKeyTest.php @@ -6,8 +6,8 @@ namespace ShlinkioCliTest\Shlink\CLI\Command; use PHPUnit\Framework\Attributes\Test; use Shlinkio\Shlink\CLI\Command\Api\GenerateKeyCommand; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\TestUtils\CliTest\CliTestCase; +use Symfony\Component\Console\Command\Command; class GenerateApiKeyTest extends CliTestCase { @@ -17,6 +17,6 @@ class GenerateApiKeyTest extends CliTestCase [$output, $exitCode] = $this->exec([GenerateKeyCommand::NAME]); self::assertStringContainsString('[OK] Generated API key', $output); - self::assertEquals(ExitCode::EXIT_SUCCESS, $exitCode); + self::assertEquals(Command::SUCCESS, $exitCode); } } diff --git a/module/CLI/test-cli/Command/ListApiKeysTest.php b/module/CLI/test-cli/Command/ListApiKeysTest.php index 9e0ce90d..0e43f24a 100644 --- a/module/CLI/test-cli/Command/ListApiKeysTest.php +++ b/module/CLI/test-cli/Command/ListApiKeysTest.php @@ -8,8 +8,8 @@ use Cake\Chronos\Chronos; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use Shlinkio\Shlink\CLI\Command\Api\ListKeysCommand; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\TestUtils\CliTest\CliTestCase; +use Symfony\Component\Console\Command\Command; class ListApiKeysTest extends CliTestCase { @@ -19,7 +19,7 @@ class ListApiKeysTest extends CliTestCase [$output, $exitCode] = $this->exec([ListKeysCommand::NAME, ...$flags]); self::assertEquals($expectedOutput, $output); - self::assertEquals(ExitCode::EXIT_SUCCESS, $exitCode); + self::assertEquals(Command::SUCCESS, $exitCode); } public static function provideFlags(): iterable diff --git a/module/CLI/test/Command/Api/DisableKeyCommandTest.php b/module/CLI/test/Command/Api/DisableKeyCommandTest.php index a617539d..e8a08336 100644 --- a/module/CLI/test/Command/Api/DisableKeyCommandTest.php +++ b/module/CLI/test/Command/Api/DisableKeyCommandTest.php @@ -8,12 +8,12 @@ use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\CLI\Command\Api\DisableKeyCommand; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Common\Exception\InvalidArgumentException; use Shlinkio\Shlink\Rest\ApiKey\Model\ApiKeyMeta; use Shlinkio\Shlink\Rest\Entity\ApiKey; use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; use ShlinkioTest\Shlink\CLI\Util\CliTestUtils; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; class DisableKeyCommandTest extends TestCase @@ -40,7 +40,7 @@ class DisableKeyCommandTest extends TestCase $output = $this->commandTester->getDisplay(); self::assertStringContainsString('API key "abcd1234" properly disabled', $output); - self::assertEquals(ExitCode::EXIT_SUCCESS, $exitCode); + self::assertEquals(Command::SUCCESS, $exitCode); } #[Test] @@ -57,7 +57,7 @@ class DisableKeyCommandTest extends TestCase $output = $this->commandTester->getDisplay(); self::assertStringContainsString('API key "the key to delete" properly disabled', $output); - self::assertEquals(ExitCode::EXIT_SUCCESS, $exitCode); + self::assertEquals(Command::SUCCESS, $exitCode); } #[Test] @@ -76,7 +76,7 @@ class DisableKeyCommandTest extends TestCase $output = $this->commandTester->getDisplay(); self::assertStringContainsString($expectedMessage, $output); - self::assertEquals(ExitCode::EXIT_FAILURE, $exitCode); + self::assertEquals(Command::FAILURE, $exitCode); } #[Test] @@ -96,7 +96,7 @@ class DisableKeyCommandTest extends TestCase $output = $this->commandTester->getDisplay(); self::assertStringContainsString($expectedMessage, $output); - self::assertEquals(ExitCode::EXIT_FAILURE, $exitCode); + self::assertEquals(Command::FAILURE, $exitCode); } #[Test] @@ -108,7 +108,7 @@ class DisableKeyCommandTest extends TestCase $exitCode = $this->commandTester->execute([], ['interactive' => false]); - self::assertEquals(ExitCode::EXIT_WARNING, $exitCode); + self::assertEquals(Command::INVALID, $exitCode); } #[Test] @@ -128,6 +128,6 @@ class DisableKeyCommandTest extends TestCase $output = $this->commandTester->getDisplay(); self::assertStringContainsString('API key "the key to delete" properly disabled', $output); - self::assertEquals(ExitCode::EXIT_SUCCESS, $exitCode); + self::assertEquals(Command::SUCCESS, $exitCode); } } diff --git a/module/CLI/test/Command/Api/GenerateKeyCommandTest.php b/module/CLI/test/Command/Api/GenerateKeyCommandTest.php index 4fa4498c..849ea0cf 100644 --- a/module/CLI/test/Command/Api/GenerateKeyCommandTest.php +++ b/module/CLI/test/Command/Api/GenerateKeyCommandTest.php @@ -10,11 +10,11 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\CLI\ApiKey\RoleResolverInterface; use Shlinkio\Shlink\CLI\Command\Api\GenerateKeyCommand; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Rest\ApiKey\Model\ApiKeyMeta; use Shlinkio\Shlink\Rest\Entity\ApiKey; use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; use ShlinkioTest\Shlink\CLI\Util\CliTestUtils; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; class GenerateKeyCommandTest extends TestCase @@ -68,6 +68,6 @@ class GenerateKeyCommandTest extends TestCase '--name' => 'Alice', ]); - self::assertEquals(ExitCode::EXIT_SUCCESS, $exitCode); + self::assertEquals(Command::SUCCESS, $exitCode); } } diff --git a/module/CLI/test/Command/Domain/ListDomainsCommandTest.php b/module/CLI/test/Command/Domain/ListDomainsCommandTest.php index 2621f940..159fded4 100644 --- a/module/CLI/test/Command/Domain/ListDomainsCommandTest.php +++ b/module/CLI/test/Command/Domain/ListDomainsCommandTest.php @@ -9,13 +9,13 @@ use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\CLI\Command\Domain\ListDomainsCommand; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Config\NotFoundRedirects; use Shlinkio\Shlink\Core\Config\Options\NotFoundRedirectOptions; use Shlinkio\Shlink\Core\Domain\DomainServiceInterface; use Shlinkio\Shlink\Core\Domain\Entity\Domain; use Shlinkio\Shlink\Core\Domain\Model\DomainItem; use ShlinkioTest\Shlink\CLI\Util\CliTestUtils; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; class ListDomainsCommandTest extends TestCase @@ -51,7 +51,7 @@ class ListDomainsCommandTest extends TestCase $this->commandTester->execute($input); self::assertEquals($expectedOutput, $this->commandTester->getDisplay()); - self::assertEquals(ExitCode::EXIT_SUCCESS, $this->commandTester->getStatusCode()); + self::assertEquals(Command::SUCCESS, $this->commandTester->getStatusCode()); } public static function provideInputsAndOutputs(): iterable diff --git a/module/CLI/test/Command/Integration/MatomoSendVisitsCommandTest.php b/module/CLI/test/Command/Integration/MatomoSendVisitsCommandTest.php index 78d2f828..f4eebdf5 100644 --- a/module/CLI/test/Command/Integration/MatomoSendVisitsCommandTest.php +++ b/module/CLI/test/Command/Integration/MatomoSendVisitsCommandTest.php @@ -8,12 +8,12 @@ use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\CLI\Command\Integration\MatomoSendVisitsCommand; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Common\Util\DateRange; use Shlinkio\Shlink\Core\Matomo\MatomoOptions; use Shlinkio\Shlink\Core\Matomo\MatomoVisitSenderInterface; use Shlinkio\Shlink\Core\Matomo\Model\SendVisitsResult; use ShlinkioTest\Shlink\CLI\Util\CliTestUtils; +use Symfony\Component\Console\Command\Command; class MatomoSendVisitsCommandTest extends TestCase { @@ -30,7 +30,7 @@ class MatomoSendVisitsCommandTest extends TestCase [$output, $exitCode] = $this->executeCommand(matomoEnabled: false); self::assertStringContainsString('Matomo integration is not enabled in this Shlink instance', $output); - self::assertEquals(ExitCode::EXIT_WARNING, $exitCode); + self::assertEquals(Command::INVALID, $exitCode); } #[Test] @@ -74,7 +74,7 @@ class MatomoSendVisitsCommandTest extends TestCase [$output, $exitCode] = $this->executeCommand(['y']); self::assertStringContainsString($expectedResultMessage, $output); - self::assertEquals(ExitCode::EXIT_SUCCESS, $exitCode); + self::assertEquals(Command::SUCCESS, $exitCode); } #[Test] diff --git a/module/CLI/test/Command/RedirectRule/ManageRedirectRulesCommandTest.php b/module/CLI/test/Command/RedirectRule/ManageRedirectRulesCommandTest.php index 79859d23..5cb45a4b 100644 --- a/module/CLI/test/Command/RedirectRule/ManageRedirectRulesCommandTest.php +++ b/module/CLI/test/Command/RedirectRule/ManageRedirectRulesCommandTest.php @@ -9,13 +9,13 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\CLI\Command\RedirectRule\ManageRedirectRulesCommand; use Shlinkio\Shlink\CLI\RedirectRule\RedirectRuleHandlerInterface; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; use Shlinkio\Shlink\Core\RedirectRule\ShortUrlRedirectRuleServiceInterface; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\ShortUrl\ShortUrlResolverInterface; use ShlinkioTest\Shlink\CLI\Util\CliTestUtils; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; class ManageRedirectRulesCommandTest extends TestCase @@ -51,7 +51,7 @@ class ManageRedirectRulesCommandTest extends TestCase $exitCode = $this->commandTester->execute(['shortCode' => 'foo']); $output = $this->commandTester->getDisplay(); - self::assertEquals(ExitCode::EXIT_FAILURE, $exitCode); + self::assertEquals(Command::FAILURE, $exitCode); self::assertStringContainsString('Short URL for foo not found', $output); } @@ -70,7 +70,7 @@ class ManageRedirectRulesCommandTest extends TestCase $exitCode = $this->commandTester->execute(['shortCode' => 'foo']); $output = $this->commandTester->getDisplay(); - self::assertEquals(ExitCode::EXIT_SUCCESS, $exitCode); + self::assertEquals(Command::SUCCESS, $exitCode); self::assertStringNotContainsString('Rules properly saved', $output); } @@ -89,7 +89,7 @@ class ManageRedirectRulesCommandTest extends TestCase $exitCode = $this->commandTester->execute(['shortCode' => 'foo']); $output = $this->commandTester->getDisplay(); - self::assertEquals(ExitCode::EXIT_SUCCESS, $exitCode); + self::assertEquals(Command::SUCCESS, $exitCode); self::assertStringContainsString('Rules properly saved', $output); } } diff --git a/module/CLI/test/Command/ShortUrl/CreateShortUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/CreateShortUrlCommandTest.php index a57a2870..728f8f22 100644 --- a/module/CLI/test/Command/ShortUrl/CreateShortUrlCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/CreateShortUrlCommandTest.php @@ -11,7 +11,6 @@ use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\CLI\Command\ShortUrl\CreateShortUrlCommand; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\Exception\NonUniqueSlugException; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; @@ -20,6 +19,7 @@ use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlCreation; use Shlinkio\Shlink\Core\ShortUrl\Model\UrlShorteningResult; use Shlinkio\Shlink\Core\ShortUrl\UrlShortenerInterface; use ShlinkioTest\Shlink\CLI\Util\CliTestUtils; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Tester\CommandTester; @@ -59,7 +59,7 @@ class CreateShortUrlCommandTest extends TestCase ], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE]); $output = $this->commandTester->getDisplay(); - self::assertEquals(ExitCode::EXIT_SUCCESS, $this->commandTester->getStatusCode()); + self::assertEquals(Command::SUCCESS, $this->commandTester->getStatusCode()); self::assertStringContainsString('stringified_short_url', $output); self::assertStringNotContainsString('but the real-time updates cannot', $output); } @@ -75,7 +75,7 @@ class CreateShortUrlCommandTest extends TestCase $this->commandTester->execute(['longUrl' => 'http://domain.com/invalid', '--custom-slug' => 'my-slug']); $output = $this->commandTester->getDisplay(); - self::assertEquals(ExitCode::EXIT_FAILURE, $this->commandTester->getStatusCode()); + self::assertEquals(Command::FAILURE, $this->commandTester->getStatusCode()); self::assertStringContainsString('Provided slug "my-slug" is already in use', $output); } @@ -99,7 +99,7 @@ class CreateShortUrlCommandTest extends TestCase ]); $output = $this->commandTester->getDisplay(); - self::assertEquals(ExitCode::EXIT_SUCCESS, $this->commandTester->getStatusCode()); + self::assertEquals(Command::SUCCESS, $this->commandTester->getStatusCode()); self::assertStringContainsString('stringified_short_url', $output); } @@ -117,7 +117,7 @@ class CreateShortUrlCommandTest extends TestCase $input['longUrl'] = 'http://domain.com/foo/bar'; $this->commandTester->execute($input); - self::assertEquals(ExitCode::EXIT_SUCCESS, $this->commandTester->getStatusCode()); + self::assertEquals(Command::SUCCESS, $this->commandTester->getStatusCode()); } public static function provideDomains(): iterable diff --git a/module/CLI/test/Command/ShortUrl/DeleteExpiredShortUrlsCommandTest.php b/module/CLI/test/Command/ShortUrl/DeleteExpiredShortUrlsCommandTest.php index ea580064..2a4b15f9 100644 --- a/module/CLI/test/Command/ShortUrl/DeleteExpiredShortUrlsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/DeleteExpiredShortUrlsCommandTest.php @@ -9,10 +9,10 @@ use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\CLI\Command\ShortUrl\DeleteExpiredShortUrlsCommand; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\ShortUrl\DeleteShortUrlServiceInterface; use Shlinkio\Shlink\Core\ShortUrl\Model\ExpiredShortUrlsConditions; use ShlinkioTest\Shlink\CLI\Util\CliTestUtils; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; class DeleteExpiredShortUrlsCommandTest extends TestCase @@ -38,7 +38,7 @@ class DeleteExpiredShortUrlsCommandTest extends TestCase $status = $this->commandTester->getStatusCode(); self::assertStringContainsString('Careful!', $output); - self::assertEquals(ExitCode::EXIT_WARNING, $status); + self::assertEquals(Command::INVALID, $status); } #[Test] @@ -62,7 +62,7 @@ class DeleteExpiredShortUrlsCommandTest extends TestCase self::assertStringNotContainsString('Careful!', $output); } self::assertStringContainsString('5 expired short URLs have been deleted', $output); - self::assertEquals(ExitCode::EXIT_SUCCESS, $status); + self::assertEquals(Command::SUCCESS, $status); } #[Test] @@ -77,7 +77,7 @@ class DeleteExpiredShortUrlsCommandTest extends TestCase self::assertStringNotContainsString('Careful!', $output); self::assertStringContainsString('There are 38 expired short URLs matching provided conditions', $output); - self::assertEquals(ExitCode::EXIT_SUCCESS, $status); + self::assertEquals(Command::SUCCESS, $status); } #[Test] diff --git a/module/CLI/test/Command/ShortUrl/DeleteShortUrlVisitsCommandTest.php b/module/CLI/test/Command/ShortUrl/DeleteShortUrlVisitsCommandTest.php index 2a281a8a..de038aef 100644 --- a/module/CLI/test/Command/ShortUrl/DeleteShortUrlVisitsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/DeleteShortUrlVisitsCommandTest.php @@ -9,11 +9,11 @@ use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\CLI\Command\ShortUrl\DeleteShortUrlVisitsCommand; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; use Shlinkio\Shlink\Core\Model\BulkDeleteResult; use Shlinkio\Shlink\Core\ShortUrl\ShortUrlVisitsDeleterInterface; use ShlinkioTest\Shlink\CLI\Util\CliTestUtils; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; class DeleteShortUrlVisitsCommandTest extends TestCase @@ -36,7 +36,7 @@ class DeleteShortUrlVisitsCommandTest extends TestCase $exitCode = $this->commandTester->execute(['shortCode' => 'foo']); $output = $this->commandTester->getDisplay(); - self::assertEquals(ExitCode::EXIT_SUCCESS, $exitCode); + self::assertEquals(Command::SUCCESS, $exitCode); self::assertStringContainsString('Operation aborted', $output); } @@ -58,7 +58,7 @@ class DeleteShortUrlVisitsCommandTest extends TestCase $exitCode = $this->commandTester->execute($args); $output = $this->commandTester->getDisplay(); - self::assertEquals(ExitCode::EXIT_WARNING, $exitCode); + self::assertEquals(Command::INVALID, $exitCode); self::assertStringContainsString($expectedError, $output); } @@ -77,7 +77,7 @@ class DeleteShortUrlVisitsCommandTest extends TestCase $exitCode = $this->commandTester->execute(['shortCode' => 'foo']); $output = $this->commandTester->getDisplay(); - self::assertEquals(ExitCode::EXIT_SUCCESS, $exitCode); + self::assertEquals(Command::SUCCESS, $exitCode); self::assertStringContainsString('Successfully deleted 5 visits', $output); } } diff --git a/module/CLI/test/Command/ShortUrl/EditShortUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/EditShortUrlCommandTest.php index f540b5dc..0fd9a860 100644 --- a/module/CLI/test/Command/ShortUrl/EditShortUrlCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/EditShortUrlCommandTest.php @@ -7,13 +7,13 @@ use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\CLI\Command\ShortUrl\EditShortUrlCommand; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifierInterface; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\ShortUrl\ShortUrlServiceInterface; use ShlinkioTest\Shlink\CLI\Util\CliTestUtils; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Tester\CommandTester; @@ -45,7 +45,7 @@ class EditShortUrlCommandTest extends TestCase $exitCode = $this->commandTester->getStatusCode(); self::assertStringContainsString('Short URL "https://s.test/foo" properly edited', $output); - self::assertEquals(ExitCode::EXIT_SUCCESS, $exitCode); + self::assertEquals(Command::SUCCESS, $exitCode); } #[Test] @@ -69,6 +69,6 @@ class EditShortUrlCommandTest extends TestCase } else { self::assertStringNotContainsString('Exception trace:', $output); } - self::assertEquals(ExitCode::EXIT_FAILURE, $exitCode); + self::assertEquals(Command::FAILURE, $exitCode); } } diff --git a/module/CLI/test/Command/Visit/DeleteOrphanVisitsCommandTest.php b/module/CLI/test/Command/Visit/DeleteOrphanVisitsCommandTest.php index cd39c63a..68eedcee 100644 --- a/module/CLI/test/Command/Visit/DeleteOrphanVisitsCommandTest.php +++ b/module/CLI/test/Command/Visit/DeleteOrphanVisitsCommandTest.php @@ -8,10 +8,10 @@ use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\CLI\Command\Visit\DeleteOrphanVisitsCommand; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Model\BulkDeleteResult; use Shlinkio\Shlink\Core\Visit\VisitsDeleterInterface; use ShlinkioTest\Shlink\CLI\Util\CliTestUtils; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; class DeleteOrphanVisitsCommandTest extends TestCase @@ -34,7 +34,7 @@ class DeleteOrphanVisitsCommandTest extends TestCase $exitCode = $this->commandTester->execute([]); $output = $this->commandTester->getDisplay(); - self::assertEquals(ExitCode::EXIT_SUCCESS, $exitCode); + self::assertEquals(Command::SUCCESS, $exitCode); self::assertStringContainsString('You are about to delete all orphan visits.', $output); self::assertStringContainsString('Successfully deleted 5 visits', $output); } diff --git a/module/CLI/test/Command/Visit/DownloadGeoLiteDbCommandTest.php b/module/CLI/test/Command/Visit/DownloadGeoLiteDbCommandTest.php index 01322f0b..3247450e 100644 --- a/module/CLI/test/Command/Visit/DownloadGeoLiteDbCommandTest.php +++ b/module/CLI/test/Command/Visit/DownloadGeoLiteDbCommandTest.php @@ -10,12 +10,12 @@ use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\CLI\Command\Visit\DownloadGeoLiteDbCommand; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Exception\GeolocationDbUpdateFailedException; use Shlinkio\Shlink\Core\Geolocation\GeolocationDbUpdaterInterface; use Shlinkio\Shlink\Core\Geolocation\GeolocationDownloadProgressHandlerInterface; use Shlinkio\Shlink\Core\Geolocation\GeolocationResult; use ShlinkioTest\Shlink\CLI\Util\CliTestUtils; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; use function sprintf; @@ -65,12 +65,12 @@ class DownloadGeoLiteDbCommandTest extends TestCase yield 'existing db' => [ true, '[WARNING] GeoLite2 db file update failed. Visits will continue to be located', - ExitCode::EXIT_WARNING, + Command::INVALID, ]; yield 'not existing db' => [ false, '[ERROR] GeoLite2 db file download failed. It will not be possible to locate', - ExitCode::EXIT_FAILURE, + Command::FAILURE, ]; } @@ -87,7 +87,7 @@ class DownloadGeoLiteDbCommandTest extends TestCase $exitCode = $this->commandTester->getStatusCode(); self::assertStringContainsString('[WARNING] ' . $expectedWarningMessage, $output); - self::assertSame(ExitCode::EXIT_WARNING, $exitCode); + self::assertSame(Command::INVALID, $exitCode); } #[Test, DataProvider('provideSuccessParams')] @@ -102,7 +102,7 @@ class DownloadGeoLiteDbCommandTest extends TestCase $exitCode = $this->commandTester->getStatusCode(); self::assertStringContainsString($expectedMessage, $output); - self::assertSame(ExitCode::EXIT_SUCCESS, $exitCode); + self::assertSame(Command::SUCCESS, $exitCode); } public static function provideSuccessParams(): iterable diff --git a/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php b/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php index aa1f5e25..1f34baef 100644 --- a/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php +++ b/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php @@ -10,7 +10,6 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\CLI\Command\Visit\DownloadGeoLiteDbCommand; use Shlinkio\Shlink\CLI\Command\Visit\LocateVisitsCommand; -use Shlinkio\Shlink\CLI\Util\ExitCode; use Shlinkio\Shlink\Core\Exception\IpCannotBeLocatedException; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\Visit\Entity\Visit; @@ -83,7 +82,7 @@ class LocateVisitsCommandTest extends TestCase $this->visitToLocation->expects( $this->exactly($expectedUnlocatedCalls + $expectedEmptyCalls + $expectedAllCalls), )->method('resolveVisitLocation')->withAnyParameters()->willReturn(Location::emptyInstance()); - $this->downloadDbCommand->method('run')->willReturn(ExitCode::EXIT_SUCCESS); + $this->downloadDbCommand->method('run')->willReturn(Command::SUCCESS); $this->commandTester->setInputs(['y']); $this->commandTester->execute($args); @@ -116,7 +115,7 @@ class LocateVisitsCommandTest extends TestCase ->withAnyParameters() ->willReturnCallback($this->invokeHelperMethods($visit, $location)); $this->visitToLocation->expects($this->once())->method('resolveVisitLocation')->willThrowException($e); - $this->downloadDbCommand->method('run')->willReturn(ExitCode::EXIT_SUCCESS); + $this->downloadDbCommand->method('run')->willReturn(Command::SUCCESS); $this->commandTester->execute([], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE]); @@ -145,7 +144,7 @@ class LocateVisitsCommandTest extends TestCase $this->visitToLocation->expects($this->once())->method('resolveVisitLocation')->willThrowException( IpCannotBeLocatedException::forError(WrongIpException::fromIpAddress('1.2.3.4')), ); - $this->downloadDbCommand->method('run')->willReturn(ExitCode::EXIT_SUCCESS); + $this->downloadDbCommand->method('run')->willReturn(Command::SUCCESS); $this->commandTester->execute([], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE]); @@ -169,7 +168,7 @@ class LocateVisitsCommandTest extends TestCase $this->visitService->expects($this->never())->method('locateUnlocatedVisits'); $this->visitToLocation->expects($this->never())->method('resolveVisitLocation'); - $this->downloadDbCommand->method('run')->willReturn(ExitCode::EXIT_SUCCESS); + $this->downloadDbCommand->method('run')->willReturn(Command::SUCCESS); $this->commandTester->execute([], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE]); $output = $this->commandTester->getDisplay(); @@ -184,7 +183,7 @@ class LocateVisitsCommandTest extends TestCase public function showsProperMessageWhenGeoLiteUpdateFails(): void { $this->lock->method('acquire')->willReturn(true); - $this->downloadDbCommand->method('run')->willReturn(ExitCode::EXIT_FAILURE); + $this->downloadDbCommand->method('run')->willReturn(Command::FAILURE); $this->visitService->expects($this->never())->method('locateUnlocatedVisits'); $this->commandTester->execute([]); @@ -197,7 +196,7 @@ class LocateVisitsCommandTest extends TestCase public function providingAllFlagOnItsOwnDisplaysNotice(): void { $this->lock->method('acquire')->willReturn(true); - $this->downloadDbCommand->method('run')->willReturn(ExitCode::EXIT_SUCCESS); + $this->downloadDbCommand->method('run')->willReturn(Command::SUCCESS); $this->commandTester->execute(['--all' => true]); $output = $this->commandTester->getDisplay(); @@ -208,7 +207,7 @@ class LocateVisitsCommandTest extends TestCase #[Test, DataProvider('provideAbortInputs')] public function processingAllCancelsCommandIfUserDoesNotActivelyAgreeToConfirmation(array $inputs): void { - $this->downloadDbCommand->method('run')->willReturn(ExitCode::EXIT_SUCCESS); + $this->downloadDbCommand->method('run')->willReturn(Command::SUCCESS); $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Execution aborted');