From 01dbffe49563e56aeda03e95121742aee87c6a21 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 13 Aug 2014 17:09:55 -0700 Subject: [PATCH 1/3] Fixed trailing slash in URL Added regular expression to remove trailing slash if included in URL. Api::__construct --- src/Jira/Api.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Jira/Api.php b/src/Jira/Api.php index b915d60..f0920c4 100644 --- a/src/Jira/Api.php +++ b/src/Jira/Api.php @@ -72,6 +72,9 @@ public function __construct( AuthenticationInterface $authentication, ClientInterface $client = null ) { + //Regular expression to remove trailing slash + $endpoint = preg_replace('{/$}', '', $endpoint); + $this->setEndPoint($endpoint); $this->authentication = $authentication; From 1f1223f219114ab27d11a0e907b496d8e3070d78 Mon Sep 17 00:00:00 2001 From: Joost Pastoor Date: Sun, 28 Feb 2016 08:41:49 +0000 Subject: [PATCH 2/3] Moved endpoint trailing slash check to setEndpoint and wrote unittest --- src/Jira/Api.php | 10 +++++----- tests/Jira/ApiTest.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 tests/Jira/ApiTest.php diff --git a/src/Jira/Api.php b/src/Jira/Api.php index f0920c4..270f131 100644 --- a/src/Jira/Api.php +++ b/src/Jira/Api.php @@ -72,9 +72,6 @@ public function __construct( AuthenticationInterface $authentication, ClientInterface $client = null ) { - //Regular expression to remove trailing slash - $endpoint = preg_replace('{/$}', '', $endpoint); - $this->setEndPoint($endpoint); $this->authentication = $authentication; @@ -101,14 +98,17 @@ public function getEndpoint() } /** - * set end point url. + * Set Endpoint URL * - * @param $url + * @param string $url */ public function setEndPoint($url) { $this->fields = array(); + // Remove trailing slash in the url + $url = rtrim($url, '/'); + $this->endpoint = $url; } diff --git a/tests/Jira/ApiTest.php b/tests/Jira/ApiTest.php new file mode 100644 index 0000000..f26dce7 --- /dev/null +++ b/tests/Jira/ApiTest.php @@ -0,0 +1,28 @@ +assertEquals('https://test.test', $api->getEndpoint()); + + // Make sure nothing is removed if there is no trailing slash + $url = 'https://urlwithouttrailing.slash'; + $api->setEndPoint($url); + $this->assertEquals($url, $api->getEndpoint()); + } +} From 239d6b4cb6a0f42f5c2adf9365da0823ecbcb6f7 Mon Sep 17 00:00:00 2001 From: Joost Pastoor Date: Sun, 28 Feb 2016 11:35:06 +0000 Subject: [PATCH 3/3] Standardized tests namespace to Tests\chobie\ --- composer.json | 2 +- tests/Jira/Api/Authentication/BasicTest.php | 8 ++++++-- tests/Jira/IssueTypeTest.php | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index f420fdf..be970a4 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ }, "autoload-dev": { "psr-4": { - "chobie\\Tests\\": "tests" + "Tests\\chobie\\": "tests" } }, "extra": { diff --git a/tests/Jira/Api/Authentication/BasicTest.php b/tests/Jira/Api/Authentication/BasicTest.php index 1b98f22..5f7610d 100644 --- a/tests/Jira/Api/Authentication/BasicTest.php +++ b/tests/Jira/Api/Authentication/BasicTest.php @@ -1,13 +1,17 @@ assertEquals($id, $basic->getId()); $this->assertEquals($pass, $basic->getPassword()); $this->assertEquals(base64_encode(sprintf("%s:%s", $id, $pass)), $basic->getCredential()); diff --git a/tests/Jira/IssueTypeTest.php b/tests/Jira/IssueTypeTest.php index be03d05..80764cf 100644 --- a/tests/Jira/IssueTypeTest.php +++ b/tests/Jira/IssueTypeTest.php @@ -1,6 +1,6 @@