From 97a362617d99dedc04a7d2f8e63faa021cb01f18 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 11 Aug 2019 14:21:35 +0200 Subject: [PATCH] Added new API test for Options requests --- .../test-api/Action/ListShortUrlsTest.php | 2 +- .../test-api/Action/OptionsRequestTest.php | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 module/Rest/test-api/Action/OptionsRequestTest.php diff --git a/module/Rest/test-api/Action/ListShortUrlsTest.php b/module/Rest/test-api/Action/ListShortUrlsTest.php index 77966214..eb1e605b 100644 --- a/module/Rest/test-api/Action/ListShortUrlsTest.php +++ b/module/Rest/test-api/Action/ListShortUrlsTest.php @@ -8,7 +8,7 @@ use ShlinkioTest\Shlink\Common\ApiTest\ApiTestCase; class ListShortUrlsTest extends ApiTestCase { /** @test */ - public function shortUrlsAreProperlyListed() + public function shortUrlsAreProperlyListed(): void { $resp = $this->callApiWithKey(self::METHOD_GET, '/short-urls'); $respPayload = $this->getJsonResponsePayload($resp); diff --git a/module/Rest/test-api/Action/OptionsRequestTest.php b/module/Rest/test-api/Action/OptionsRequestTest.php new file mode 100644 index 00000000..121e9328 --- /dev/null +++ b/module/Rest/test-api/Action/OptionsRequestTest.php @@ -0,0 +1,31 @@ +callApi(self::METHOD_OPTIONS, '/short-urls'); + + $this->assertEquals(self::STATUS_NO_CONTENT, $resp->getStatusCode()); + $this->assertEmpty((string) $resp->getBody()); + } + + /** @test */ + public function optionsRequestsReturnAllowedMethodsForEndpoint(): void + { + $resp = $this->callApi(self::METHOD_OPTIONS, '/short-urls'); + $allowedMethods = $resp->getHeaderLine('Allow'); + + $this->assertEquals([ + self::METHOD_GET, + self::METHOD_POST, + ], explode(',', $allowedMethods)); + } +}