diff --git a/bin/test/run-api-tests.sh b/bin/test/run-api-tests.sh index 75a51387..cbc10a1a 100755 --- a/bin/test/run-api-tests.sh +++ b/bin/test/run-api-tests.sh @@ -9,7 +9,7 @@ echo 'Starting server...' vendor/bin/zend-expressive-swoole start -d sleep 2 -vendor/bin/phpunit --order-by=random -c phpunit-api.xml --testdox --colors=always +vendor/bin/phpunit --order-by=random -c phpunit-api.xml --testdox --colors=always $* testsExitCode=$? vendor/bin/zend-expressive-swoole stop diff --git a/module/Rest/src/Util/RestUtils.php b/module/Rest/src/Util/RestUtils.php index d4ad46dc..3b56fef0 100644 --- a/module/Rest/src/Util/RestUtils.php +++ b/module/Rest/src/Util/RestUtils.php @@ -9,6 +9,7 @@ use Shlinkio\Shlink\Core\Exception as Core; use Shlinkio\Shlink\Rest\Exception as Rest; use Throwable; +/** @deprecated */ class RestUtils { public const INVALID_SHORTCODE_ERROR = 'INVALID_SHORTCODE'; @@ -24,7 +25,8 @@ class RestUtils public const NOT_FOUND_ERROR = 'NOT_FOUND'; public const UNKNOWN_ERROR = 'UNKNOWN_ERROR'; - public static function getRestErrorCodeFromException(Throwable $e) + /** @deprecated */ + public static function getRestErrorCodeFromException(Throwable $e): string { switch (true) { case $e instanceof Core\InvalidShortCodeException: diff --git a/module/Rest/test-api/Action/EditShortUrlActionTest.php b/module/Rest/test-api/Action/EditShortUrlActionTest.php new file mode 100644 index 00000000..65f2fd1d --- /dev/null +++ b/module/Rest/test-api/Action/EditShortUrlActionTest.php @@ -0,0 +1,34 @@ +callApiWithKey(self::METHOD_PATCH, '/short-urls/invalid', [RequestOptions::JSON => []]); + ['error' => $error] = $this->getJsonResponsePayload($resp); + + $this->assertEquals(self::STATUS_NOT_FOUND, $resp->getStatusCode()); + $this->assertEquals(RestUtils::INVALID_SHORTCODE_ERROR, $error); + } + + /** @test */ + public function providingInvalidDataReturnsBadRequest(): void + { + $resp = $this->callApiWithKey(self::METHOD_PATCH, '/short-urls/invalid', [RequestOptions::JSON => [ + 'maxVisits' => 'not_a_number', + ]]); + ['error' => $error] = $this->getJsonResponsePayload($resp); + + $this->assertEquals(self::STATUS_BAD_REQUEST, $resp->getStatusCode()); + $this->assertEquals(RestUtils::INVALID_ARGUMENT_ERROR, $error); + } +}