diff --git a/config/autoload/middleware-pipeline.global.php b/config/autoload/middleware-pipeline.global.php index dc17bd53..308315bb 100644 --- a/config/autoload/middleware-pipeline.global.php +++ b/config/autoload/middleware-pipeline.global.php @@ -1,12 +1,8 @@ [ ErrorHandler::class, Expressive\Helper\ContentLengthMiddleware::class, - LocaleMiddleware::class, + Common\Middleware\LocaleMiddleware::class, ], - 'priority' => 11, + 'priority' => 12, ], 'pre-routing-rest' => [ 'path' => '/rest', 'middleware' => [ - PathVersionMiddleware::class, + Rest\Middleware\PathVersionMiddleware::class, + Rest\Middleware\ShortUrl\ShortCodePathMiddleware::class, ], 'priority' => 11, ], @@ -39,10 +36,10 @@ return [ 'rest' => [ 'path' => '/rest', 'middleware' => [ - CrossDomainMiddleware::class, + Rest\Middleware\CrossDomainMiddleware::class, Expressive\Router\Middleware\ImplicitOptionsMiddleware::class, - BodyParserMiddleware::class, - CheckAuthenticationMiddleware::class, + Rest\Middleware\BodyParserMiddleware::class, + Rest\Middleware\CheckAuthenticationMiddleware::class, ], 'priority' => 5, ], @@ -50,7 +47,7 @@ return [ 'post-routing' => [ 'middleware' => [ Expressive\Router\Middleware\DispatchMiddleware::class, - NotFoundHandler::class, + Core\Response\NotFoundHandler::class, ], 'priority' => 1, ], diff --git a/docs/swagger/paths/v1_authenticate.json b/docs/swagger/paths/v1_authenticate.json index 55160087..49a690fb 100644 --- a/docs/swagger/paths/v1_authenticate.json +++ b/docs/swagger/paths/v1_authenticate.json @@ -1,5 +1,6 @@ { "post": { + "operationId": "authenticate", "tags": [ "Authentication" ], diff --git a/docs/swagger/paths/v1_short-codes.json b/docs/swagger/paths/v1_short-codes.json index 48d16a16..80c950e8 100644 --- a/docs/swagger/paths/v1_short-codes.json +++ b/docs/swagger/paths/v1_short-codes.json @@ -1,7 +1,8 @@ { "get": { + "operationId": "listShortUrls", "tags": [ - "ShortCodes" + "Short URLs" ], "summary": "List short URLs", "description": "Returns the list of short codes", @@ -142,8 +143,9 @@ }, "post": { + "operationId": "createShortUrl", "tags": [ - "ShortCodes" + "Short URLs" ], "summary": "Create short URL", "description": "Creates a new short code", diff --git a/docs/swagger/paths/v1_short-codes_shorten.json b/docs/swagger/paths/v1_short-codes_shorten.json index 1ee3387c..cb3fd18b 100644 --- a/docs/swagger/paths/v1_short-codes_shorten.json +++ b/docs/swagger/paths/v1_short-codes_shorten.json @@ -1,7 +1,8 @@ { "get": { + "operationId": "shortenUrl", "tags": [ - "ShortCodes" + "Short URLs" ], "summary": "Create a short URL", "description": "Creates a short URL in a single API call. Useful for third party integrations", diff --git a/docs/swagger/paths/v1_short-codes_{shortCode}.json b/docs/swagger/paths/v1_short-codes_{shortCode}.json index e17881af..e6ad06f2 100644 --- a/docs/swagger/paths/v1_short-codes_{shortCode}.json +++ b/docs/swagger/paths/v1_short-codes_{shortCode}.json @@ -1,7 +1,8 @@ { "get": { + "operationId": "getShortUrl", "tags": [ - "ShortCodes" + "Short URLs" ], "summary": "Parse short code", "description": "Get the long URL behind a short code.", @@ -78,8 +79,9 @@ }, "put": { + "operationId": "editShortUrl", "tags": [ - "ShortCodes" + "Short URLs" ], "summary": "Edit short code", "description": "Update certain meta arguments from an existing short URL.", @@ -162,8 +164,9 @@ }, "delete": { + "operationId": "deleteShortUrl", "tags": [ - "ShortCodes" + "Short URLs" ], "summary": "Delete short code", "description": "Deletes the short URL for provided short code.", diff --git a/docs/swagger/paths/v1_short-codes_{shortCode}_tags.json b/docs/swagger/paths/v1_short-codes_{shortCode}_tags.json index 7a1c1759..d3bb8b86 100644 --- a/docs/swagger/paths/v1_short-codes_{shortCode}_tags.json +++ b/docs/swagger/paths/v1_short-codes_{shortCode}_tags.json @@ -1,8 +1,8 @@ { "put": { + "operationId": "editShortUrlTags", "tags": [ - "ShortCodes", - "Tags" + "Short URLs" ], "summary": "Edit tags on short URL", "description": "Edit the tags on provided short code.", @@ -10,7 +10,7 @@ { "name": "shortCode", "in": "path", - "description": "The shortCode in which we want to edit tags.", + "description": "The short code for the short URL in which we want to edit tags.", "required": true, "schema": { "type": "string" diff --git a/docs/swagger/paths/v1_short-codes_{shortCode}_visits.json b/docs/swagger/paths/v1_short-codes_{shortCode}_visits.json index ec8d372e..a59fd5d4 100644 --- a/docs/swagger/paths/v1_short-codes_{shortCode}_visits.json +++ b/docs/swagger/paths/v1_short-codes_{shortCode}_visits.json @@ -1,7 +1,7 @@ { "get": { + "operationId": "getShortUrlVisits", "tags": [ - "ShortCodes", "Visits" ], "summary": "List visits for short URL", @@ -10,7 +10,7 @@ { "name": "shortCode", "in": "path", - "description": "The shortCode from which we want to get the visits.", + "description": "The short code for the short URL from which we want to get the visits.", "required": true, "schema": { "type": "string" diff --git a/docs/swagger/paths/v1_tags.json b/docs/swagger/paths/v1_tags.json index b33b9606..fb4df70d 100644 --- a/docs/swagger/paths/v1_tags.json +++ b/docs/swagger/paths/v1_tags.json @@ -1,5 +1,6 @@ { "get": { + "operationId": "listTags", "tags": [ "Tags" ], @@ -60,6 +61,7 @@ }, "post": { + "operationId": "createTags", "tags": [ "Tags" ], @@ -143,6 +145,7 @@ }, "put": { + "operationId": "renameTag", "tags": [ "Tags" ], @@ -216,6 +219,7 @@ }, "delete": { + "operationId": "deleteTags", "tags": [ "Tags" ], diff --git a/docs/swagger/swagger.json b/docs/swagger/swagger.json index c5dbd791..8dec455c 100644 --- a/docs/swagger/swagger.json +++ b/docs/swagger/swagger.json @@ -32,21 +32,40 @@ } }, + "tags": [ + { + "name": "Authentication", + "description": "Authentication-related endpoints" + }, + { + "name": "Short URLs", + "description": "Operations that can be performed on short URLs" + }, + { + "name": "Tags", + "description": "Let you handle the list of available tags" + }, + { + "name": "Visits", + "description": "Operations to manage visits on short URLs" + } + ], + "paths": { "/v1/authenticate": { "$ref": "paths/v1_authenticate.json" }, - "/v1/short-codes": { + "/v1/short-urls": { "$ref": "paths/v1_short-codes.json" }, - "/v1/short-codes/shorten": { + "/v1/short-urls/shorten": { "$ref": "paths/v1_short-codes_shorten.json" }, - "/v1/short-codes/{shortCode}": { + "/v1/short-urls/{shortCode}": { "$ref": "paths/v1_short-codes_{shortCode}.json" }, - "/v1/short-codes/{shortCode}/tags": { + "/v1/short-urls/{shortCode}/tags": { "$ref": "paths/v1_short-codes_{shortCode}_tags.json" }, @@ -54,7 +73,7 @@ "$ref": "paths/v1_tags.json" }, - "/v1/short-codes/{shortCode}/visits": { + "/v1/short-urls/{shortCode}/visits": { "$ref": "paths/v1_short-codes_{shortCode}_visits.json" } } diff --git a/module/Core/src/Model/CreateShortCodeData.php b/module/Core/src/Model/CreateShortUrlData.php similarity index 96% rename from module/Core/src/Model/CreateShortCodeData.php rename to module/Core/src/Model/CreateShortUrlData.php index 880c32c2..a1d9d018 100644 --- a/module/Core/src/Model/CreateShortCodeData.php +++ b/module/Core/src/Model/CreateShortUrlData.php @@ -5,7 +5,7 @@ namespace Shlinkio\Shlink\Core\Model; use Psr\Http\Message\UriInterface; -final class CreateShortCodeData +final class CreateShortUrlData { /** * @var UriInterface diff --git a/module/Rest/config/auth.config.php b/module/Rest/config/auth.config.php index b43c333f..c60cc358 100644 --- a/module/Rest/config/auth.config.php +++ b/module/Rest/config/auth.config.php @@ -8,7 +8,7 @@ return [ 'auth' => [ 'routes_whitelist' => [ Action\AuthenticateAction::class, - Action\ShortCode\SingleStepCreateShortCodeAction::class, + Action\ShortUrl\SingleStepCreateShortUrlAction::class, ], ], diff --git a/module/Rest/config/dependencies.config.php b/module/Rest/config/dependencies.config.php index ae500a22..c9a9da98 100644 --- a/module/Rest/config/dependencies.config.php +++ b/module/Rest/config/dependencies.config.php @@ -1,12 +1,11 @@ [ 'factories' => [ - JWTService::class => ConfigAbstractFactory::class, + Authentication\JWTService::class => ConfigAbstractFactory::class, ApiKeyService::class => ConfigAbstractFactory::class, Action\AuthenticateAction::class => ConfigAbstractFactory::class, - Action\ShortCode\CreateShortCodeAction::class => ConfigAbstractFactory::class, - Action\ShortCode\SingleStepCreateShortCodeAction::class => ConfigAbstractFactory::class, - Action\ShortCode\EditShortCodeAction::class => ConfigAbstractFactory::class, - Action\ShortCode\DeleteShortCodeAction::class => ConfigAbstractFactory::class, - Action\ShortCode\ResolveUrlAction::class => ConfigAbstractFactory::class, + Action\ShortUrl\CreateShortUrlAction::class => ConfigAbstractFactory::class, + Action\ShortUrl\SingleStepCreateShortUrlAction::class => ConfigAbstractFactory::class, + Action\ShortUrl\EditShortUrlAction::class => ConfigAbstractFactory::class, + Action\ShortUrl\DeleteShortUrlAction::class => ConfigAbstractFactory::class, + Action\ShortUrl\ResolveShortUrlAction::class => ConfigAbstractFactory::class, Action\Visit\GetVisitsAction::class => ConfigAbstractFactory::class, - Action\ShortCode\ListShortCodesAction::class => ConfigAbstractFactory::class, - Action\ShortCode\EditShortCodeTagsAction::class => ConfigAbstractFactory::class, + Action\ShortUrl\ListShortUrlsAction::class => ConfigAbstractFactory::class, + Action\ShortUrl\EditShortUrlTagsAction::class => ConfigAbstractFactory::class, Action\Tag\ListTagsAction::class => ConfigAbstractFactory::class, Action\Tag\DeleteTagsAction::class => ConfigAbstractFactory::class, Action\Tag\CreateTagsAction::class => ConfigAbstractFactory::class, @@ -37,47 +36,53 @@ return [ Middleware\CrossDomainMiddleware::class => InvokableFactory::class, Middleware\PathVersionMiddleware::class => InvokableFactory::class, Middleware\CheckAuthenticationMiddleware::class => ConfigAbstractFactory::class, - Middleware\ShortCode\CreateShortCodeContentNegotiationMiddleware::class => InvokableFactory::class, + Middleware\ShortUrl\CreateShortUrlContentNegotiationMiddleware::class => InvokableFactory::class, + Middleware\ShortUrl\ShortCodePathMiddleware::class => InvokableFactory::class, ], ], ConfigAbstractFactory::class => [ - JWTService::class => [AppOptions::class], + Authentication\JWTService::class => [AppOptions::class], ApiKeyService::class => ['em'], - Action\AuthenticateAction::class => [ApiKeyService::class, JWTService::class, 'translator', 'Logger_Shlink'], - Action\ShortCode\CreateShortCodeAction::class => [ + Action\AuthenticateAction::class => [ + ApiKeyService::class, + Authentication\JWTService::class, + 'translator', + 'Logger_Shlink', + ], + Action\ShortUrl\CreateShortUrlAction::class => [ Service\UrlShortener::class, 'translator', 'config.url_shortener.domain', 'Logger_Shlink', ], - Action\ShortCode\SingleStepCreateShortCodeAction::class => [ + Action\ShortUrl\SingleStepCreateShortUrlAction::class => [ Service\UrlShortener::class, 'translator', ApiKeyService::class, 'config.url_shortener.domain', 'Logger_Shlink', ], - Action\ShortCode\EditShortCodeAction::class => [Service\ShortUrlService::class, 'translator', 'Logger_Shlink'], - Action\ShortCode\DeleteShortCodeAction::class => [ + Action\ShortUrl\EditShortUrlAction::class => [Service\ShortUrlService::class, 'translator', 'Logger_Shlink'], + Action\ShortUrl\DeleteShortUrlAction::class => [ Service\ShortUrl\DeleteShortUrlService::class, 'translator', 'Logger_Shlink', ], - Action\ShortCode\ResolveUrlAction::class => [ + Action\ShortUrl\ResolveShortUrlAction::class => [ Service\UrlShortener::class, 'translator', 'config.url_shortener.domain', ], Action\Visit\GetVisitsAction::class => [Service\VisitsTracker::class, 'translator', 'Logger_Shlink'], - Action\ShortCode\ListShortCodesAction::class => [ + Action\ShortUrl\ListShortUrlsAction::class => [ Service\ShortUrlService::class, 'translator', 'config.url_shortener.domain', 'Logger_Shlink', ], - Action\ShortCode\EditShortCodeTagsAction::class => [ + Action\ShortUrl\EditShortUrlTagsAction::class => [ Service\ShortUrlService::class, 'translator', 'Logger_Shlink', @@ -88,7 +93,7 @@ return [ Action\Tag\UpdateTagAction::class => [Service\Tag\TagService::class, Translator::class, LoggerInterface::class], Middleware\CheckAuthenticationMiddleware::class => [ - JWTService::class, + Authentication\JWTService::class, 'translator', 'config.auth.routes_whitelist', 'Logger_Shlink', diff --git a/module/Rest/config/routes.config.php b/module/Rest/config/routes.config.php index 7058ad59..a937bc42 100644 --- a/module/Rest/config/routes.config.php +++ b/module/Rest/config/routes.config.php @@ -11,17 +11,17 @@ return [ Action\AuthenticateAction::getRouteDef(), // Short codes - Action\ShortCode\CreateShortCodeAction::getRouteDef([ - Middleware\ShortCode\CreateShortCodeContentNegotiationMiddleware::class, + Action\ShortUrl\CreateShortUrlAction::getRouteDef([ + Middleware\ShortUrl\CreateShortUrlContentNegotiationMiddleware::class, ]), - Action\ShortCode\SingleStepCreateShortCodeAction::getRouteDef([ - Middleware\ShortCode\CreateShortCodeContentNegotiationMiddleware::class, + Action\ShortUrl\SingleStepCreateShortUrlAction::getRouteDef([ + Middleware\ShortUrl\CreateShortUrlContentNegotiationMiddleware::class, ]), - Action\ShortCode\EditShortCodeAction::getRouteDef(), - Action\ShortCode\DeleteShortCodeAction::getRouteDef(), - Action\ShortCode\ResolveUrlAction::getRouteDef(), - Action\ShortCode\ListShortCodesAction::getRouteDef(), - Action\ShortCode\EditShortCodeTagsAction::getRouteDef(), + Action\ShortUrl\EditShortUrlAction::getRouteDef(), + Action\ShortUrl\DeleteShortUrlAction::getRouteDef(), + Action\ShortUrl\ResolveShortUrlAction::getRouteDef(), + Action\ShortUrl\ListShortUrlsAction::getRouteDef(), + Action\ShortUrl\EditShortUrlTagsAction::getRouteDef(), // Visits Action\Visit\GetVisitsAction::getRouteDef(), diff --git a/module/Rest/src/Action/ShortCode/AbstractCreateShortCodeAction.php b/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php similarity index 81% rename from module/Rest/src/Action/ShortCode/AbstractCreateShortCodeAction.php rename to module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php index 833f49c6..db5d9818 100644 --- a/module/Rest/src/Action/ShortCode/AbstractCreateShortCodeAction.php +++ b/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php @@ -1,7 +1,7 @@ buildUrlToShortCodeData($request); - $shortCodeMeta = $shortCodeData->getMeta(); - $longUrl = $shortCodeData->getLongUrl(); - $customSlug = $shortCodeMeta->getCustomSlug(); + $shortUrlData = $this->buildShortUrlData($request); + $shortUrlMeta = $shortUrlData->getMeta(); + $longUrl = $shortUrlData->getLongUrl(); + $customSlug = $shortUrlMeta->getCustomSlug(); } catch (InvalidArgumentException $e) { $this->logger->warning('Provided data is invalid.' . PHP_EOL . $e); return new JsonResponse([ @@ -67,11 +67,11 @@ abstract class AbstractCreateShortCodeAction extends AbstractRestAction try { $shortUrl = $this->urlShortener->urlToShortCode( $longUrl, - $shortCodeData->getTags(), - $shortCodeMeta->getValidSince(), - $shortCodeMeta->getValidUntil(), + $shortUrlData->getTags(), + $shortUrlMeta->getValidSince(), + $shortUrlMeta->getValidUntil(), $customSlug, - $shortCodeMeta->getMaxVisits() + $shortUrlMeta->getMaxVisits() ); $transformer = new ShortUrlDataTransformer($this->domainConfig); @@ -95,7 +95,7 @@ abstract class AbstractCreateShortCodeAction extends AbstractRestAction ), ], self::STATUS_BAD_REQUEST); } catch (\Throwable $e) { - $this->logger->error('Unexpected error creating shortcode.' . PHP_EOL . $e); + $this->logger->error('Unexpected error creating short url.' . PHP_EOL . $e); return new JsonResponse([ 'error' => RestUtils::UNKNOWN_ERROR, 'message' => $this->translator->translate('Unexpected error occurred'), @@ -105,8 +105,8 @@ abstract class AbstractCreateShortCodeAction extends AbstractRestAction /** * @param Request $request - * @return CreateShortCodeData + * @return CreateShortUrlData * @throws InvalidArgumentException */ - abstract protected function buildUrlToShortCodeData(Request $request): CreateShortCodeData; + abstract protected function buildShortUrlData(Request $request): CreateShortUrlData; } diff --git a/module/Rest/src/Action/ShortCode/CreateShortCodeAction.php b/module/Rest/src/Action/ShortUrl/CreateShortUrlAction.php similarity index 74% rename from module/Rest/src/Action/ShortCode/CreateShortCodeAction.php rename to module/Rest/src/Action/ShortUrl/CreateShortUrlAction.php index da556420..696c47b3 100644 --- a/module/Rest/src/Action/ShortCode/CreateShortCodeAction.php +++ b/module/Rest/src/Action/ShortUrl/CreateShortUrlAction.php @@ -1,33 +1,34 @@ getParsedBody(); if (! isset($postData['longUrl'])) { throw new InvalidArgumentException($this->translator->translate('A URL was not provided')); } - return new CreateShortCodeData( + return new CreateShortUrlData( new Uri($postData['longUrl']), (array) ($postData['tags'] ?? []), ShortUrlMeta::createFromParams( diff --git a/module/Rest/src/Action/ShortCode/DeleteShortCodeAction.php b/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php similarity index 93% rename from module/Rest/src/Action/ShortCode/DeleteShortCodeAction.php rename to module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php index 8fa9ca5b..d752cc9b 100644 --- a/module/Rest/src/Action/ShortCode/DeleteShortCodeAction.php +++ b/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php @@ -1,7 +1,7 @@ getQueryParams(); @@ -55,6 +55,6 @@ class SingleStepCreateShortCodeAction extends AbstractCreateShortCodeAction throw new InvalidArgumentException($this->translator->translate('A URL was not provided')); } - return new CreateShortCodeData(new Uri($query['longUrl'])); + return new CreateShortUrlData(new Uri($query['longUrl'])); } } diff --git a/module/Rest/src/Action/Visit/GetVisitsAction.php b/module/Rest/src/Action/Visit/GetVisitsAction.php index 96010ce0..3d5890cc 100644 --- a/module/Rest/src/Action/Visit/GetVisitsAction.php +++ b/module/Rest/src/Action/Visit/GetVisitsAction.php @@ -16,7 +16,7 @@ use Zend\I18n\Translator\TranslatorInterface; class GetVisitsAction extends AbstractRestAction { - protected const ROUTE_PATH = '/short-codes/{shortCode}/visits'; + protected const ROUTE_PATH = '/short-urls/{shortCode}/visits'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; /** @@ -58,7 +58,7 @@ class GetVisitsAction extends AbstractRestAction ], ]); } catch (InvalidArgumentException $e) { - $this->logger->warning('Provided nonexistent shortcode' . PHP_EOL . $e); + $this->logger->warning('Provided nonexistent short code' . PHP_EOL . $e); return new JsonResponse([ 'error' => RestUtils::getRestErrorCodeFromException($e), 'message' => sprintf( diff --git a/module/Rest/src/Middleware/ShortCode/CreateShortCodeContentNegotiationMiddleware.php b/module/Rest/src/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddleware.php similarity index 94% rename from module/Rest/src/Middleware/ShortCode/CreateShortCodeContentNegotiationMiddleware.php rename to module/Rest/src/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddleware.php index 3a2f0f4d..8ea8f259 100644 --- a/module/Rest/src/Middleware/ShortCode/CreateShortCodeContentNegotiationMiddleware.php +++ b/module/Rest/src/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddleware.php @@ -1,7 +1,7 @@ getUri(); + $path = $uri->getPath(); + + // If the path starts with the old prefix, replace it by the new one + return $handler->handle( + $request->withUri($uri->withPath(\str_replace(self::OLD_PATH_PREFIX, self::NEW_PATH_PREFIX, $path))) + ); + } +} diff --git a/module/Rest/src/Util/RestUtils.php b/module/Rest/src/Util/RestUtils.php index c783f6cb..35b6cbc9 100644 --- a/module/Rest/src/Util/RestUtils.php +++ b/module/Rest/src/Util/RestUtils.php @@ -10,6 +10,7 @@ use Shlinkio\Shlink\Rest\Exception as Rest; class RestUtils { public const INVALID_SHORTCODE_ERROR = 'INVALID_SHORTCODE'; + // FIXME Should be INVALID_SHORT_URL_DELETION public const INVALID_SHORTCODE_DELETION_ERROR = 'INVALID_SHORTCODE_DELETION'; public const INVALID_URL_ERROR = 'INVALID_URL'; public const INVALID_ARGUMENT_ERROR = 'INVALID_ARGUMENT'; diff --git a/module/Rest/test/Action/ShortCode/CreateShortCodeActionTest.php b/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php similarity index 92% rename from module/Rest/test/Action/ShortCode/CreateShortCodeActionTest.php rename to module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php index 8b7afe7c..d4d4e63c 100644 --- a/module/Rest/test/Action/ShortCode/CreateShortCodeActionTest.php +++ b/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php @@ -1,7 +1,7 @@ urlShortener = $this->prophesize(UrlShortener::class); - $this->action = new CreateShortCodeAction($this->urlShortener->reveal(), Translator::factory([]), [ + $this->action = new CreateShortUrlAction($this->urlShortener->reveal(), Translator::factory([]), [ 'schema' => 'http', 'hostname' => 'foo.com', ]); diff --git a/module/Rest/test/Action/ShortCode/DeleteShortCodeActionTest.php b/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php similarity index 86% rename from module/Rest/test/Action/ShortCode/DeleteShortCodeActionTest.php rename to module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php index 3c5a5c87..abcd61cf 100644 --- a/module/Rest/test/Action/ShortCode/DeleteShortCodeActionTest.php +++ b/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php @@ -1,23 +1,23 @@ service = $this->prophesize(DeleteShortUrlServiceInterface::class); - $this->action = new DeleteShortCodeAction($this->service->reveal(), Translator::factory([])); + $this->action = new DeleteShortUrlAction($this->service->reveal(), Translator::factory([])); } /** diff --git a/module/Rest/test/Action/ShortCode/EditShortCodeActionTest.php b/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php similarity index 90% rename from module/Rest/test/Action/ShortCode/EditShortCodeActionTest.php rename to module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php index e96ccdf8..e0cfb13e 100644 --- a/module/Rest/test/Action/ShortCode/EditShortCodeActionTest.php +++ b/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php @@ -1,7 +1,7 @@ shortUrlService = $this->prophesize(ShortUrlServiceInterface::class); - $this->action = new EditShortCodeAction($this->shortUrlService->reveal(), Translator::factory([])); + $this->action = new EditShortUrlAction($this->shortUrlService->reveal(), Translator::factory([])); } /** diff --git a/module/Rest/test/Action/ShortCode/EditShortCodeTagsActionTest.php b/module/Rest/test/Action/ShortUrl/EditShortUrlTagsActionTest.php similarity index 86% rename from module/Rest/test/Action/ShortCode/EditShortCodeTagsActionTest.php rename to module/Rest/test/Action/ShortUrl/EditShortUrlTagsActionTest.php index d7eab463..dc4b4a5c 100644 --- a/module/Rest/test/Action/ShortCode/EditShortCodeTagsActionTest.php +++ b/module/Rest/test/Action/ShortUrl/EditShortUrlTagsActionTest.php @@ -1,21 +1,21 @@ shortUrlService = $this->prophesize(ShortUrlService::class); - $this->action = new EditShortCodeTagsAction($this->shortUrlService->reveal(), Translator::factory([])); + $this->action = new EditShortUrlTagsAction($this->shortUrlService->reveal(), Translator::factory([])); } /** diff --git a/module/Rest/test/Action/ShortCode/ListShortCodesActionTest.php b/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php similarity index 84% rename from module/Rest/test/Action/ShortCode/ListShortCodesActionTest.php rename to module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php index 7c414e44..eecbb8d8 100644 --- a/module/Rest/test/Action/ShortCode/ListShortCodesActionTest.php +++ b/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php @@ -1,21 +1,21 @@ service = $this->prophesize(ShortUrlService::class); - $this->action = new ListShortCodesAction($this->service->reveal(), Translator::factory([]), [ + $this->action = new ListShortUrlsAction($this->service->reveal(), Translator::factory([]), [ 'hostname' => 'doma.in', 'schema' => 'https', ]); diff --git a/module/Rest/test/Action/ShortCode/ResolveUrlActionTest.php b/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php similarity index 91% rename from module/Rest/test/Action/ShortCode/ResolveUrlActionTest.php rename to module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php index bde3e89a..a6159ec1 100644 --- a/module/Rest/test/Action/ShortCode/ResolveUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php @@ -1,7 +1,7 @@ urlShortener = $this->prophesize(UrlShortener::class); - $this->action = new ResolveUrlAction($this->urlShortener->reveal(), Translator::factory([]), []); + $this->action = new ResolveShortUrlAction($this->urlShortener->reveal(), Translator::factory([]), []); } /** diff --git a/module/Rest/test/Action/ShortCode/SingleStepCreateShortCodeActionTest.php b/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php similarity index 92% rename from module/Rest/test/Action/ShortCode/SingleStepCreateShortCodeActionTest.php rename to module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php index 0a7d6981..438132cb 100644 --- a/module/Rest/test/Action/ShortCode/SingleStepCreateShortCodeActionTest.php +++ b/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php @@ -1,7 +1,7 @@ urlShortener = $this->prophesize(UrlShortenerInterface::class); $this->apiKeyService = $this->prophesize(ApiKeyServiceInterface::class); - $this->action = new SingleStepCreateShortCodeAction( + $this->action = new SingleStepCreateShortUrlAction( $this->urlShortener->reveal(), Translator::factory([]), $this->apiKeyService->reveal(), diff --git a/module/Rest/test/Middleware/ShortCode/CreateShortCodeContentNegotiationMiddlewareTest.php b/module/Rest/test/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddlewareTest.php similarity index 90% rename from module/Rest/test/Middleware/ShortCode/CreateShortCodeContentNegotiationMiddlewareTest.php rename to module/Rest/test/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddlewareTest.php index 450b9e1c..bb2dc7ad 100644 --- a/module/Rest/test/Middleware/ShortCode/CreateShortCodeContentNegotiationMiddlewareTest.php +++ b/module/Rest/test/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddlewareTest.php @@ -1,21 +1,21 @@ middleware = new CreateShortCodeContentNegotiationMiddleware(); + $this->middleware = new CreateShortUrlContentNegotiationMiddleware(); $this->requestHandler = $this->prophesize(RequestHandlerInterface::class); } diff --git a/module/Rest/test/Middleware/ShortUrl/ShortCodePathMiddlewareTest.php b/module/Rest/test/Middleware/ShortUrl/ShortCodePathMiddlewareTest.php new file mode 100644 index 00000000..d28acf40 --- /dev/null +++ b/module/Rest/test/Middleware/ShortUrl/ShortCodePathMiddlewareTest.php @@ -0,0 +1,50 @@ +middleware = new ShortCodePathMiddleware(); + $this->requestHandler = $this->prophesize(RequestHandlerInterface::class); + $this->requestHandler->handle(Argument::type(ServerRequestInterface::class))->willReturn(new Response()); + } + + /** + * @test + */ + public function properlyReplacesTheOldPathByTheNewOne() + { + $uri = new Uri('/short-codes/foo'); + + $request = $this->prophesize(ServerRequestInterface::class); + $request->getUri()->willReturn($uri); + $withUri = $request->withUri(Argument::that(function (UriInterface $uri) { + $path = $uri->getPath(); + + Assert::assertContains('/short-urls', $path); + Assert::assertNotContains('/short-codes', $path); + + return $uri; + }))->willReturn($request->reveal()); + + $this->middleware->process($request->reveal(), $this->requestHandler->reveal()); + + $withUri->shouldHaveBeenCalledTimes(1); + } +}