Skip to content

Commit ecc9ce2

Browse files
committed
Added a series of unit tests
1 parent 44919a8 commit ecc9ce2

10 files changed

+30
-31
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
1111
- The `$params` argument of the `Api::getWorklogs` method is now optional by [@aik099] (#244).
1212
- The `$params` argument of the `Api::getTransitions` method is now optional by [@aik099] (#244).
1313
- Changed default `Api::api` parameter $return_as_array to TRUE by [@jpastoor] (#137).
14-
- Api methods (except those that return issue lists) now consistently return as associative arrays instead of Result class instance by [@jpastoor] (#137).
14+
- Api methods (except those that return issue lists) now consistently return as associative arrays instead of Result by [@jpastoor] (#137).
1515

1616
### Removed
1717
...

src/Jira/Api.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,41 +267,41 @@ public function getProjects()
267267
/**
268268
* Returns one 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 getProject($project_key)
274+
public function getProject($project_id_or_key)
275275
{
276-
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s', $project_key));
276+
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s', $project_id_or_key));
277277
}
278278

279279
/**
280280
* Returns all roles of a project.
281281
*
282-
* @param string $project_key Project key.
282+
* @param string $project_id_or_key Project ID or key.
283283
*
284284
* @return array
285285
* @link https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-project-roles/#api-rest-api-2-role-get
286286
*/
287-
public function getRoles($project_key)
287+
public function getRoles($project_id_or_key)
288288
{
289-
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s/role', $project_key));
289+
return $this->api(self::REQUEST_GET, sprintf('/rest/api/2/project/%s/role', $project_id_or_key));
290290
}
291291

292292
/**
293293
* Returns role details.
294294
*
295-
* @param string $project_key Project key.
296-
* @param integer $role_id Role ID.
295+
* @param string $project_id_or_key Project ID or key.
296+
* @param integer $role_id Role ID.
297297
*
298298
* @return array|false
299299
*/
300-
public function getRoleDetails($project_key, $role_id)
300+
public function getRoleDetails($project_id_or_key, $role_id)
301301
{
302302
return $this->api(
303303
self::REQUEST_GET,
304-
sprintf('/rest/api/2/project/%s/role/%s', $project_key, $role_id)
304+
sprintf('/rest/api/2/project/%s/role/%s', $project_id_or_key, $role_id)
305305
);
306306
}
307307

src/Jira/Api/Client/CurlClient.php

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

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

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

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

tests/Jira/AbstractApiTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function setUpTest()
5757
*
5858
* @return void
5959
*/
60-
protected function assertApiResponse($expected_raw_response, $actual_response, $wrap_in_result = true)
60+
protected function assertApiResponse($expected_raw_response, $actual_response, $wrap_in_result = false)
6161
{
6262
$expected = json_decode($expected_raw_response, true);
6363

tests/Jira/ApiTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public function testSearch()
5050

5151
$this->assertApiResponse(
5252
$response,
53-
$this->api->search('test', 5, 2, 'description')
53+
$this->api->search('test', 5, 2, 'description'),
54+
true
5455
);
5556
}
5657

@@ -75,7 +76,7 @@ public function testSetWatchers()
7576
$this->assertEquals(
7677
array(
7778
false,
78-
new Result(json_decode($errored_response, true)),
79+
json_decode($errored_response, true),
7980
),
8081
$this->api->setWatchers('JRE-123', array('account-id-one', 'account-id-two'))
8182
);
@@ -207,7 +208,7 @@ public function testResponseIsJsonDecodedIntoArray()
207208

208209
$this->assertEquals(
209210
array('key' => 'value'),
210-
$this->api->api(api::REQUEST_GET, '/rest/api/2/something', array(), true)
211+
$this->api->api(api::REQUEST_GET, '/rest/api/2/something')
211212
);
212213
}
213214

@@ -222,7 +223,7 @@ public function testResponseIsJsonDecodedIntoResultObject()
222223

223224
$this->assertEquals(
224225
new Result(array('key' => 'value')),
225-
$this->api->api(api::REQUEST_GET, '/rest/api/2/something')
226+
$this->api->api(api::REQUEST_GET, '/rest/api/2/something', array(), false)
226227
);
227228
}
228229

@@ -477,7 +478,7 @@ public function testGetCreateMeta(
477478
// Perform the API call.
478479
$actual = $this->api->getCreateMeta($project_ids, $project_keys, $issue_type_ids, $issue_type_names, $expand);
479480

480-
$this->assertApiResponse($response, $actual, false);
481+
$this->assertApiResponse($response, $actual);
481482
}
482483

483484
public static function getCreateMetaDataProvider()

tests/Jira/IssueAttachmentsApiTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function testGetAttachment()
8989
$response
9090
);
9191

92-
$this->assertApiResponse($response, $this->api->getAttachment('18700'), false);
92+
$this->assertApiResponse($response, $this->api->getAttachment('18700'));
9393
}
9494

9595
}

tests/Jira/IssueWorklogsApiTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testAddWorkLogWithoutCustomParams($time_spent, array $expected_r
4343
$response
4444
);
4545

46-
$this->assertApiResponse($response, $this->api->addWorklog('JRA-15', $time_spent), false);
46+
$this->assertApiResponse($response, $this->api->addWorklog('JRA-15', $time_spent));
4747
}
4848

4949
public static function addWorkLogWithoutCustomParamsDataProvider()
@@ -68,8 +68,7 @@ public function testAddWorklogWithCustomParams()
6868

6969
$this->assertApiResponse(
7070
$response,
71-
$this->api->addWorklog('JRA-15', '12m', array('started' => $started)),
72-
false
71+
$this->api->addWorklog('JRA-15', '12m', array('started' => $started))
7372
);
7473
}
7574

@@ -84,7 +83,7 @@ public function testDeleteWorkLogWithoutCustomParams()
8483
$response
8584
);
8685

87-
$this->assertApiResponse($response, $this->api->deleteWorklog('JRA-15', 11256), false);
86+
$this->assertApiResponse($response, $this->api->deleteWorklog('JRA-15', 11256));
8887
}
8988

9089
public function testDeleteWorkLogWithCustomParams()
@@ -100,8 +99,7 @@ public function testDeleteWorkLogWithCustomParams()
10099

101100
$this->assertApiResponse(
102101
$response,
103-
$this->api->deleteWorklog('JRA-15', 11256, array('custom' => 'param')),
104-
false
102+
$this->api->deleteWorklog('JRA-15', 11256, array('custom' => 'param'))
105103
);
106104
}
107105

tests/Jira/ProjectRolesApiTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function testGetProjectRoles()
2121
$response
2222
);
2323

24-
$this->assertApiResponse($response, $this->api->getRoles($project_id), false);
24+
$this->assertApiResponse($response, $this->api->getRoles($project_id));
2525
}
2626

2727
public function testGetProjectRoleDetails()
@@ -37,7 +37,7 @@ public function testGetProjectRoleDetails()
3737
$response
3838
);
3939

40-
$this->assertApiResponse($response, $this->api->getRoleDetails($project_id, $role_id), false);
40+
$this->assertApiResponse($response, $this->api->getRoleDetails($project_id, $role_id));
4141
}
4242

4343
}

tests/Jira/ProjectVersionsApiTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function testGetVersions()
2121
$response
2222
);
2323

24-
$this->assertApiResponse($response, $this->api->getVersions($project_key), false);
24+
$this->assertApiResponse($response, $this->api->getVersions($project_key));
2525
}
2626

2727
public function testCreateVersionWithoutCustomParams()

tests/Jira/ProjectsApiTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testGetProject()
3333
$response
3434
);
3535

36-
$this->assertApiResponse($response, $this->api->getProject('TST'), false);
36+
$this->assertApiResponse($response, $this->api->getProject('TST'));
3737
}
3838

3939
public function testGetProjectComponents()
@@ -46,7 +46,7 @@ public function testGetProjectComponents()
4646
$response
4747
);
4848

49-
$this->assertApiResponse($response, $this->api->getProjectComponents('TST'), false);
49+
$this->assertApiResponse($response, $this->api->getProjectComponents('TST'));
5050
}
5151

5252
public function testGetProjectIssueTypes()
@@ -59,7 +59,7 @@ public function testGetProjectIssueTypes()
5959
$response
6060
);
6161

62-
$this->assertApiResponse($response, $this->api->getProjectIssueTypes('TST'), false);
62+
$this->assertApiResponse($response, $this->api->getProjectIssueTypes('TST'));
6363
}
6464

6565
}

0 commit comments

Comments
 (0)