diff --git a/module/Rest/src/Action/CreateShortcodeAction.php b/module/Rest/src/Action/CreateShortcodeAction.php index 3f249c0d..fdecedef 100644 --- a/module/Rest/src/Action/CreateShortcodeAction.php +++ b/module/Rest/src/Action/CreateShortcodeAction.php @@ -66,9 +66,10 @@ class CreateShortcodeAction extends AbstractRestAction ], 400); } $longUrl = $postData['longUrl']; + $tags = isset($postData['tags']) && is_array($postData['tags']) ? $postData['tags'] : []; try { - $shortCode = $this->urlShortener->urlToShortCode(new Uri($longUrl)); + $shortCode = $this->urlShortener->urlToShortCode(new Uri($longUrl), $tags); $shortUrl = (new Uri())->withPath($shortCode) ->withScheme($this->domainConfig['schema']) ->withHost($this->domainConfig['hostname']); diff --git a/module/Rest/test/Action/CreateShortcodeActionTest.php b/module/Rest/test/Action/CreateShortcodeActionTest.php index dcc56bf6..c3b9e3ff 100644 --- a/module/Rest/test/Action/CreateShortcodeActionTest.php +++ b/module/Rest/test/Action/CreateShortcodeActionTest.php @@ -47,8 +47,9 @@ class CreateShortcodeActionTest extends TestCase */ public function properShortcodeConversionReturnsData() { - $this->urlShortener->urlToShortCode(Argument::type(Uri::class))->willReturn('abc123') - ->shouldBeCalledTimes(1); + $this->urlShortener->urlToShortCode(Argument::type(Uri::class), Argument::type('array')) + ->willReturn('abc123') + ->shouldBeCalledTimes(1); $request = ServerRequestFactory::fromGlobals()->withParsedBody([ 'longUrl' => 'http://www.domain.com/foo/bar', @@ -63,8 +64,9 @@ class CreateShortcodeActionTest extends TestCase */ public function anInvalidUrlReturnsError() { - $this->urlShortener->urlToShortCode(Argument::type(Uri::class))->willThrow(InvalidUrlException::class) - ->shouldBeCalledTimes(1); + $this->urlShortener->urlToShortCode(Argument::type(Uri::class), Argument::type('array')) + ->willThrow(InvalidUrlException::class) + ->shouldBeCalledTimes(1); $request = ServerRequestFactory::fromGlobals()->withParsedBody([ 'longUrl' => 'http://www.domain.com/foo/bar', @@ -79,8 +81,9 @@ class CreateShortcodeActionTest extends TestCase */ public function aGenericExceptionWillReturnError() { - $this->urlShortener->urlToShortCode(Argument::type(Uri::class))->willThrow(\Exception::class) - ->shouldBeCalledTimes(1); + $this->urlShortener->urlToShortCode(Argument::type(Uri::class), Argument::type('array')) + ->willThrow(\Exception::class) + ->shouldBeCalledTimes(1); $request = ServerRequestFactory::fromGlobals()->withParsedBody([ 'longUrl' => 'http://www.domain.com/foo/bar',