Skip to content

Commit 85c17ec

Browse files
committed
Unit tests for addComment and getWorklogs
1 parent 7668f36 commit 85c17ec

File tree

5 files changed

+157
-5
lines changed

5 files changed

+157
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2424
- Added local cache to `Api::getResolutions` by [@jpastoor].
2525
- Renamed `Api::api` parameter $return_as_json to $return_as_array by [@jpastoor].
2626
- Changed default `Api::api` parameter $return_as_array to TRUE by [@jpastoor].
27-
- Api methods (except those that return issue lists) now consistently return as associative arrays instead of Result by [@jpastoor].
27+
- Api methods (except those that return issue lists) now consistently return as associative arrays instead of Result class instance by [@jpastoor].
2828

2929
### Removed
3030
...

src/Jira/Api.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public function getCreateMeta(
352352
* Add a comment to a ticket.
353353
*
354354
* @param string $issue_key Issue key should be "YOURPROJ-221".
355-
* @param array|string $params Params.
355+
* @param array|string $params Params or body string.
356356
*
357357
* @return array|false
358358
*/
@@ -377,7 +377,7 @@ public function addComment($issue_key, $params)
377377
* @return array|false
378378
* @since 2.0.0
379379
*/
380-
public function getWorklogs($issue_key, array $params)
380+
public function getWorklogs($issue_key, array $params = array())
381381
{
382382
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/issue/%s/worklog', $issue_key), $params);
383383
}
@@ -390,7 +390,7 @@ public function getWorklogs($issue_key, array $params)
390390
*
391391
* @return array|false
392392
*/
393-
public function getTransitions($issue_key, array $params)
393+
public function getTransitions($issue_key, array $params = array())
394394
{
395395
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/issue/%s/transitions', $issue_key), $params);
396396
}

tests/Jira/ApiTest.php

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ public function testGetRoles()
381381

382382
public function testGetRoleDetails()
383383
{
384-
$response = file_get_contents(__DIR__ . '/resources/api_get_roles_of_project_by_id.json');
384+
$response = file_get_contents(__DIR__ . '/resources/api_get_role_of_project_by_id.json');
385385
$project_id = '10500';
386386
$role_id = '10200';
387387

@@ -398,6 +398,46 @@ public function testGetRoleDetails()
398398
$this->assertEquals($expected, $actual);
399399
}
400400

401+
public function testAddComment()
402+
{
403+
$response = file_get_contents(__DIR__ . '/resources/api_add_comment.json');
404+
$issue_key = 'POR-1';
405+
406+
// Testing the case where the description is provided directly instead of params
407+
$description = 'testdesc';
408+
409+
$this->expectClientCall(
410+
Api::REQUEST_POST,
411+
'/rest/api/2/issue/' . $issue_key . '/comment',
412+
array('body' => $description),
413+
$response
414+
);
415+
416+
$actual = $this->api->addComment($issue_key, $description);
417+
418+
$expected = json_decode($response, true);
419+
$this->assertEquals($expected, $actual);
420+
}
421+
422+
public function testGetWorklog()
423+
{
424+
$response = file_get_contents(__DIR__ . '/resources/api_get_roles_of_project.json');
425+
$issue_key = 'POR-1';
426+
427+
$this->expectClientCall(
428+
Api::REQUEST_GET,
429+
'/rest/api/2/issue/' . $issue_key . '/worklog',
430+
array(),
431+
$response
432+
);
433+
434+
$actual = $this->api->getWorklogs($issue_key);
435+
436+
$expected = json_decode($response, true);
437+
$this->assertEquals($expected, $actual);
438+
}
439+
440+
401441
/**
402442
* Expects a particular client call.
403443
*
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"self": "http://www.example.com/jira/rest/api/2/issue/10010/comment/10000",
3+
"id": "10000",
4+
"author": {
5+
"self": "http://www.example.com/jira/rest/api/2/user?username=fred",
6+
"name": "fred",
7+
"displayName": "Fred F. User",
8+
"active": false
9+
},
10+
"body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget venenatis elit. Duis eu justo eget augue iaculis fermentum. Sed semper quam laoreet nisi egestas at posuere augue semper.",
11+
"updateAuthor": {
12+
"self": "http://www.example.com/jira/rest/api/2/user?username=fred",
13+
"name": "fred",
14+
"displayName": "Fred F. User",
15+
"active": false
16+
},
17+
"created": "2016-08-17T12:37:37.987+0000",
18+
"updated": "2016-08-17T12:37:37.987+0000",
19+
"visibility": {
20+
"type": "role",
21+
"value": "Administrators"
22+
}
23+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"startAt": 0,
3+
"maxResults": 2,
4+
"total": 2,
5+
"worklogs": [
6+
{
7+
"self": "https://test.atlassian.net/rest/api/2/issue/10100/worklog/10001",
8+
"author": {
9+
"self": "https://test.atlassian.net/rest/api/2/user?username=joost",
10+
"name": "joost",
11+
"key": "joost",
12+
"emailAddress": "[email protected]",
13+
"avatarUrls": {
14+
"48x48": "https://test.atlassian.net/secure/useravatar?ownerId=joost&avatarId=10500",
15+
"24x24": "https://test.atlassian.net/secure/useravatar?size=small&ownerId=joost&avatarId=10500",
16+
"16x16": "https://test.atlassian.net/secure/useravatar?size=xsmall&ownerId=joost&avatarId=10500",
17+
"32x32": "https://test.atlassian.net/secure/useravatar?size=medium&ownerId=joost&avatarId=10500"
18+
},
19+
"displayName": "Joost Pastoor",
20+
"active": true,
21+
"timeZone": "Europe/Berlin"
22+
},
23+
"updateAuthor": {
24+
"self": "https://test.atlassian.net/rest/api/2/user?username=joost",
25+
"name": "joost",
26+
"key": "joost",
27+
"emailAddress": "[email protected]",
28+
"avatarUrls": {
29+
"48x48": "https://test.atlassian.net/secure/useravatar?ownerId=joost&avatarId=10500",
30+
"24x24": "https://test.atlassian.net/secure/useravatar?size=small&ownerId=joost&avatarId=10500",
31+
"16x16": "https://test.atlassian.net/secure/useravatar?size=xsmall&ownerId=joost&avatarId=10500",
32+
"32x32": "https://test.atlassian.net/secure/useravatar?size=medium&ownerId=joost&avatarId=10500"
33+
},
34+
"displayName": "Joost Pastoor",
35+
"active": true,
36+
"timeZone": "Europe/Berlin"
37+
},
38+
"comment": "",
39+
"created": "2013-05-13T15:53:48.236+0200",
40+
"updated": "2013-05-13T15:53:48.236+0200",
41+
"started": "2013-05-13T15:53:00.000+0200",
42+
"timeSpent": "1d",
43+
"timeSpentSeconds": 28800,
44+
"id": "10001",
45+
"issueId": "10100"
46+
},
47+
{
48+
"self": "https://test.atlassian.net/rest/api/2/issue/10100/worklog/31214",
49+
"author": {
50+
"self": "https://test.atlassian.net/rest/api/2/user?username=joost",
51+
"name": "joost",
52+
"key": "joost",
53+
"emailAddress": "[email protected]",
54+
"avatarUrls": {
55+
"48x48": "https://test.atlassian.net/secure/useravatar?ownerId=joost&avatarId=10500",
56+
"24x24": "https://test.atlassian.net/secure/useravatar?size=small&ownerId=joost&avatarId=10500",
57+
"16x16": "https://test.atlassian.net/secure/useravatar?size=xsmall&ownerId=joost&avatarId=10500",
58+
"32x32": "https://test.atlassian.net/secure/useravatar?size=medium&ownerId=joost&avatarId=10500"
59+
},
60+
"displayName": "Joost Pastoor",
61+
"active": true,
62+
"timeZone": "Europe/Berlin"
63+
},
64+
"updateAuthor": {
65+
"self": "https://test.atlassian.net/rest/api/2/user?username=joost",
66+
"name": "joost",
67+
"key": "joost",
68+
"emailAddress": "[email protected]",
69+
"avatarUrls": {
70+
"48x48": "https://test.atlassian.net/secure/useravatar?ownerId=joost&avatarId=10500",
71+
"24x24": "https://test.atlassian.net/secure/useravatar?size=small&ownerId=joost&avatarId=10500",
72+
"16x16": "https://test.atlassian.net/secure/useravatar?size=xsmall&ownerId=joost&avatarId=10500",
73+
"32x32": "https://test.atlassian.net/secure/useravatar?size=medium&ownerId=joost&avatarId=10500"
74+
},
75+
"displayName": "Joost Pastoor",
76+
"active": true,
77+
"timeZone": "Europe/Berlin"
78+
},
79+
"comment": "",
80+
"created": "2016-08-03T16:57:15.840+0200",
81+
"updated": "2016-08-03T16:57:15.840+0200",
82+
"started": "2013-05-01T16:56:00.000+0200",
83+
"timeSpent": "2w",
84+
"timeSpentSeconds": 288000,
85+
"id": "31214",
86+
"issueId": "10100"
87+
}
88+
]
89+
}

0 commit comments

Comments
 (0)