Skip to content

Commit 109b043

Browse files
intro custom index path
1 parent 953e98b commit 109b043

File tree

4 files changed

+51
-19
lines changed

4 files changed

+51
-19
lines changed

lib/API/Client.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class Client
4949
private $grantType = 'client_credentials';
5050

5151

52+
/**
53+
* @var string
54+
*/
55+
private $indexPath = '/index.php';
56+
5257
/**
5358
* @var null
5459
*/
@@ -185,6 +190,23 @@ private function setPath($path)
185190
return $this;
186191
}
187192

193+
/**
194+
* @return string
195+
*/
196+
public function getIndexPath()
197+
{
198+
return $this->indexPath;
199+
}
200+
201+
/**
202+
* @param string $indexPath
203+
* @return $this;
204+
*/
205+
public function setIndexPath($indexPath)
206+
{
207+
$this->indexPath = $indexPath;
208+
return $this;
209+
}
188210

189211
/**
190212
* @param HTTPRequest $request

lib/API/HTTPRequest.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
class HTTPRequest {
24-
const INDEX_PATH = '/symfony/web/index.php';
24+
2525
const GET_TOKEN_END_POINT = 'oauth/issueToken';
2626

2727
/**
@@ -37,7 +37,7 @@ class HTTPRequest {
3737
/**
3838
* @var bool
3939
*/
40-
private $isShortUrl = false;
40+
private $indexPath = '/index.php';
4141

4242
/**
4343
* @var string
@@ -98,18 +98,18 @@ public function setParams($params)
9898
/**
9999
* @return boolean
100100
*/
101-
public function isShortUrl()
101+
public function getIndexPath()
102102
{
103-
return $this->isShortUrl;
103+
return $this->indexPath;
104104
}
105105

106106
/**
107-
* @param boolean $isShortUrl
107+
* @param boolean $indexPath
108108
* @return $this;
109109
*/
110-
public function setIsShortUrl($isShortUrl)
110+
public function setIndexPath($indexPath)
111111
{
112-
$this->isShortUrl = $isShortUrl;
112+
$this->indexPath = $indexPath;
113113
return $this;
114114
}
115115

@@ -135,22 +135,17 @@ public function setBasePath($basePath)
135135
* @return string
136136
*/
137137
public function buildEndPoint(){
138-
$indexPath = null ;
139-
if(!$this->isShortUrl()){
140-
$indexPath = self::INDEX_PATH;
141-
}
142-
return $this->getBasePath().$indexPath.'/api/'.$this->getApiVersion().'/'.$this->getEndPoint();
138+
139+
return $this->getBasePath().$this->getIndexPath().'/api/'.$this->getApiVersion().'/'.$this->getEndPoint();
143140

144141
}
145142

146143
/**
147144
* @return string
148145
*/
149146
public function getTokenEndPoint() {
150-
if($this->isShortUrl()){
151-
return self::GET_TOKEN_END_POINT;
152-
}
153-
return $this->getBasePath().self::INDEX_PATH.'/'.self::GET_TOKEN_END_POINT;
147+
148+
return $this->getBasePath().$this->getIndexPath().'/'.self::GET_TOKEN_END_POINT;
154149
}
155150

156151
/**

test/ClientTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ClientTest extends PHPUnit_Framework_TestCase
2727

2828
protected function setUp()
2929
{
30-
$this->client = new Client('http://orangehrm.os','testclient','testpass');
30+
$this->client = new Client('https://api-sample-cs.orangehrm.com','testclient','testpass');
3131
}
3232

3333
public function testGetToken(){
@@ -39,6 +39,7 @@ public function testGetToken(){
3939
public function testGetRequest() {
4040
$request = new HTTPRequest('employee/search');
4141
$result = $this->client->get($request);
42+
4243
$this->assertArrayHasKey('data',$result->getResult());
4344
}
4445
}

test/HTTPRequestTest.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,28 @@ protected function setUp() {
3030
$this->httpRequest = new HTTPRequest();
3131
}
3232

33-
public function testBuildEndPointWhenEmptyEndPoint() {
33+
public function testBuildEndPointWhenEmployeeEndPoint() {
3434
$this->httpRequest->setEndPoint('employee/search');
3535
$result = $this->httpRequest->buildEndPoint();
36-
$this->assertEquals('/symfony/web/index.php/api/v1/employee/search',$result);
36+
$this->assertEquals('/index.php/api/v1/employee/search',$result);
3737
}
3838

3939
public function testGetTokenEndPoint() {
4040

41+
$result = $this->httpRequest->getTokenEndPoint();
42+
$this->assertEquals('/index.php/oauth/issueToken',$result);
43+
}
44+
45+
public function testBuildEndPointWhenEmployeeEndPointWithCustomIndexPath() {
46+
$this->httpRequest->setEndPoint('employee/search');
47+
$this->httpRequest->setIndexPath('/symfony/web/index.php');
48+
$result = $this->httpRequest->buildEndPoint();
49+
$this->assertEquals('/symfony/web/index.php/api/v1/employee/search',$result);
50+
}
51+
52+
public function testGetTokenEndPointWithCustomIndexPath() {
53+
54+
$this->httpRequest->setIndexPath('/symfony/web/index.php');
4155
$result = $this->httpRequest->getTokenEndPoint();
4256
$this->assertEquals('/symfony/web/index.php/oauth/issueToken',$result);
4357
}

0 commit comments

Comments
 (0)