Skip to content

Commit 737cf10

Browse files
committed
Moved endpoint trailing slash check to setEndpoint and wrote unittest
1 parent 5475cd9 commit 737cf10

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/Jira/Api.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ public function __construct(
7272
AuthenticationInterface $authentication,
7373
ClientInterface $client = null
7474
) {
75-
//Regular expression to remove trailing slash
76-
$endpoint = preg_replace('{/$}', '', $endpoint);
77-
7875
$this->setEndPoint($endpoint);
7976
$this->authentication = $authentication;
8077

@@ -109,6 +106,9 @@ public function setEndPoint($url)
109106
{
110107
$this->fields = array();
111108

109+
//Regular expression to remove trailing slash
110+
$url = rtrim($url, '/');
111+
112112
$this->endpoint = $url;
113113
}
114114

tests/Jira/ApiTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Tests\chobie\Jira;
4+
5+
use chobie\Jira\Api;
6+
use chobie\Jira\Api\Authentication\Anonymous;
7+
8+
/**
9+
* Class ApiTest
10+
*
11+
* @package Tests\chobie\Jira
12+
*/
13+
class ApiTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/**
16+
* Tests that any trailing slash in the endpoint url is removed before being stored in the object state
17+
*/
18+
public function testSetEndpointTrailingSlash()
19+
{
20+
$api = new Api('https://test.test/', new Anonymous(), null);
21+
$this->assertEquals('https://test.test', $api->getEndpoint());
22+
}
23+
}

0 commit comments

Comments
 (0)