Skip to content

Commit 7668f36

Browse files
committed
Added a series of unit tests
1 parent a33afca commit 7668f36

12 files changed

+651
-14
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2121
- Minimal supported PHP version changed from 5.2 to 5.3 by [@chobie].
2222
- The `Api::getPriorties` renamed into `Api::getPriorities` by [@josevh].
2323
- Remove trailing slash from endpoint url by [@Procta].
24-
- Added local cache to getResolutions by [@jpastoor].
25-
- Renamed Api::api() parameter $return_as_json to $return_as_array by [@jpastoor].
26-
- Changed default Api::api() parameter $return_as_array to TRUE by [@jpastoor].
24+
- Added local cache to `Api::getResolutions` by [@jpastoor].
25+
- Renamed `Api::api` parameter $return_as_json to $return_as_array by [@jpastoor].
26+
- Changed default `Api::api` parameter $return_as_array to TRUE by [@jpastoor].
2727
- Api methods (except those that return issue lists) now consistently return as associative arrays instead of Result by [@jpastoor].
2828

2929
### Removed

src/Jira/Api.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -255,38 +255,38 @@ public function getProjects()
255255
/**
256256
* Returns one project.
257257
*
258-
* @param string $project_key Project key.
258+
* @param string $project_id_or_key Project ID or key.
259259
*
260260
* @return array|false
261261
*/
262-
public function getProject($project_key)
262+
public function getProject($project_id_or_key)
263263
{
264-
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s', $project_key));
264+
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s', $project_id_or_key));
265265
}
266266

267267
/**
268268
* Returns all roles of a project.
269269
*
270-
* @param string $project_key Project key.
270+
* @param string $project_id_or_key Project ID or key.
271271
*
272272
* @return array|false
273273
*/
274-
public function getRoles($project_key)
274+
public function getRoles($project_id_or_key)
275275
{
276-
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s/role', $project_key));
276+
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s/role', $project_id_or_key));
277277
}
278278

279279
/**
280280
* Returns role details.
281281
*
282-
* @param string $project_key Project key.
283-
* @param string $role_id Role ID.
282+
* @param string $project_id_or_key Project ID or key.
283+
* @param string $role_id Role ID.
284284
*
285285
* @return array|false
286286
*/
287-
public function getRoleDetails($project_key, $role_id)
287+
public function getRoleDetails($project_id_or_key, $role_id)
288288
{
289-
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s/role/%s', $project_key, $role_id));
289+
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s/role/%s', $project_id_or_key, $role_id));
290290
}
291291

292292
/**

src/Jira/Api/Client/CurlClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ public function sendRequest(
137137

138138
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
139139

140-
// If empty result and status != "204 No Content".
141140
if ( $http_code == 401 ) {
142141
throw new UnauthorizedException('Unauthorized');
143142
}
144143

144+
// If empty result and status != "204 No Content".
145145
if ( $response === '' && !in_array($http_code, array(201, 204)) ) {
146146
throw new Exception('JIRA Rest server returns unexpected result.');
147147
}

tests/Jira/ApiTest.php

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,147 @@ public function testGetPriorities()
257257
$this->assertEquals($expected, $this->api->getPriorities(), 'Calling twice did not yield the same results');
258258
}
259259

260+
public function testGetIssue()
261+
{
262+
$response = file_get_contents(__DIR__ . '/resources/api_get_issue.json');
263+
264+
$issue_key = 'POR-1';
265+
266+
$this->expectClientCall(
267+
Api::REQUEST_GET,
268+
'/rest/api/2/issue/' . $issue_key,
269+
array('expand' => ''),
270+
$response
271+
);
272+
273+
$actual = $this->api->getIssue($issue_key);
274+
275+
$expected = json_decode($response, true);
276+
$this->assertEquals($expected, $actual);
277+
}
278+
279+
public function testEditIssue()
280+
{
281+
$issue_key = 'POR-1';
282+
$params = array('update' => (object) array('summary' => array( (object) array("set" => "Bug in business logic"))));
283+
$this->expectClientCall(
284+
Api::REQUEST_PUT,
285+
'/rest/api/2/issue/' . $issue_key,
286+
$params,
287+
false // False is returned because there is no content (204).
288+
);
289+
290+
$actual = $this->api->editIssue($issue_key, $params);
291+
$this->assertEquals(false, $actual);
292+
}
293+
294+
public function testGetAttachmentsMetaInformation()
295+
{
296+
$response = file_get_contents(__DIR__ . '/resources/api_get_attachments_meta.json');
297+
298+
$this->expectClientCall(
299+
Api::REQUEST_GET,
300+
'/rest/api/2/attachment/meta',
301+
array(),
302+
$response
303+
);
304+
305+
$actual = $this->api->getAttachmentsMetaInformation();
306+
307+
$expected = json_decode($response, true);
308+
$this->assertEquals($expected, $actual);
309+
}
310+
311+
public function testGetAttachment()
312+
{
313+
$response = file_get_contents(__DIR__ . '/resources/api_get_attachment.json');
314+
$attachment_id = '18700';
315+
316+
$this->expectClientCall(
317+
Api::REQUEST_GET,
318+
'/rest/api/2/attachment/' . $attachment_id,
319+
array(),
320+
$response
321+
);
322+
323+
$actual = $this->api->getAttachment($attachment_id);
324+
325+
$expected = json_decode($response, true);
326+
$this->assertEquals($expected, $actual);
327+
}
328+
329+
public function testGetProjects()
330+
{
331+
$response = file_get_contents(__DIR__ . '/resources/api_get_projects.json');
332+
333+
$this->expectClientCall(
334+
Api::REQUEST_GET,
335+
'/rest/api/2/project',
336+
array(),
337+
$response
338+
);
339+
340+
$actual = $this->api->getProjects();
341+
342+
$expected = json_decode($response, true);
343+
$this->assertEquals($expected, $actual);
344+
}
345+
346+
public function testGetProject()
347+
{
348+
$response = file_get_contents(__DIR__ . '/resources/api_get_project.json');
349+
$project_id = '10500';
350+
351+
$this->expectClientCall(
352+
Api::REQUEST_GET,
353+
'/rest/api/2/project/' . $project_id,
354+
array(),
355+
$response
356+
);
357+
358+
$actual = $this->api->getProject($project_id);
359+
360+
$expected = json_decode($response, true);
361+
$this->assertEquals($expected, $actual);
362+
}
363+
364+
public function testGetRoles()
365+
{
366+
$response = file_get_contents(__DIR__ . '/resources/api_get_roles_of_project.json');
367+
$project_id = '10500';
368+
369+
$this->expectClientCall(
370+
Api::REQUEST_GET,
371+
'/rest/api/2/project/' . $project_id . '/role',
372+
array(),
373+
$response
374+
);
375+
376+
$actual = $this->api->getRoles($project_id);
377+
378+
$expected = json_decode($response, true);
379+
$this->assertEquals($expected, $actual);
380+
}
381+
382+
public function testGetRoleDetails()
383+
{
384+
$response = file_get_contents(__DIR__ . '/resources/api_get_roles_of_project_by_id.json');
385+
$project_id = '10500';
386+
$role_id = '10200';
387+
388+
$this->expectClientCall(
389+
Api::REQUEST_GET,
390+
'/rest/api/2/project/' . $project_id . '/role/' . $role_id,
391+
array(),
392+
$response
393+
);
394+
395+
$actual = $this->api->getRoleDetails($project_id, $role_id);
396+
397+
$expected = json_decode($response, true);
398+
$this->assertEquals($expected, $actual);
399+
}
400+
260401
/**
261402
* Expects a particular client call.
262403
*
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"self": "https://test.atlassian.net/rest/api/2/attachment/18700",
3+
"filename": "2016-04-04 10.02.45.jpg",
4+
"author": {
5+
"self": "https://test.atlassian.net/rest/api/2/user?username=joost.pastoor",
6+
"key": "joost.pastoor",
7+
"name": "joost.pastoor",
8+
"avatarUrls": {
9+
"16x16": "https://test.atlassian.net/secure/useravatar?size=xsmall&ownerId=joost.pastoor&avatarId=10502",
10+
"24x24": "https://test.atlassian.net/secure/useravatar?size=small&ownerId=joost.pastoor&avatarId=10502",
11+
"32x32": "https://test.atlassian.net/secure/useravatar?size=medium&ownerId=joost.pastoor&avatarId=10502",
12+
"48x48": "https://test.atlassian.net/secure/useravatar?ownerId=joost.pastoor&avatarId=10502"
13+
},
14+
"displayName": "Ernst van Rijn",
15+
"active": true
16+
},
17+
"created": "2016-04-04T10:04:07.537+0200",
18+
"size": 4097662,
19+
"mimeType": "image/jpeg",
20+
"properties": {},
21+
"content": "https://test.atlassian.net/secure/attachment/18700/2016-04-04+10.02.45.jpg",
22+
"thumbnail": "https://test.atlassian.net/secure/thumbnail/18700/_thumb_18700.png"
23+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"enabled": true,
3+
"uploadLimit": 10485760
4+
}

0 commit comments

Comments
 (0)