Skip to content

Commit 7328538

Browse files
authored
Merge pull request #246 from aik099/test-refactoring
Use same custom assert method for checking array/Result API method responses
2 parents c07c4d0 + f28ef7d commit 7328538

7 files changed

+28
-46
lines changed

tests/Jira/AbstractApiTestCase.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,18 @@ protected function setUpTest()
5252
/**
5353
* Checks, that response is correct.
5454
*
55-
* @param string $expected_raw_response Expected raw response.
56-
* @param Result|false $actual_response Actual response.
55+
* @param string $expected_raw_response Expected raw response.
56+
* @param array|Result|false $actual_response Actual response.
5757
*
5858
* @return void
5959
*/
60-
protected function assertApiResponse($expected_raw_response, $actual_response)
60+
protected function assertApiResponse($expected_raw_response, $actual_response, $wrap_in_result = true)
6161
{
62-
$expected = new Result(json_decode($expected_raw_response, true));
62+
$expected = json_decode($expected_raw_response, true);
63+
64+
if ( $wrap_in_result ) {
65+
$expected = new Result($expected);
66+
}
6367

6468
// You'll get "false", when unexpected API call was made.
6569
if ( $actual_response !== false ) {

tests/Jira/ApiTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,8 @@ public function testGetCreateMeta(
476476

477477
// Perform the API call.
478478
$actual = $this->api->getCreateMeta($project_ids, $project_keys, $issue_type_ids, $issue_type_names, $expand);
479-
$response_decoded = json_decode($response, true);
480479

481-
$this->assertEquals($response_decoded, $actual, 'The decoded response does not match the actual result.');
480+
$this->assertApiResponse($response, $actual, false);
482481
}
483482

484483
public static function getCreateMetaDataProvider()

tests/Jira/IssueAttachmentsApiTest.php

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

92-
$this->assertEquals(
93-
json_decode($response, true),
94-
$this->api->getAttachment('18700')
95-
);
92+
$this->assertApiResponse($response, $this->api->getAttachment('18700'), false);
9693
}
9794

9895
}

tests/Jira/IssueWorklogsApiTest.php

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

46-
$actual = $this->api->addWorklog('JRA-15', $time_spent);
47-
48-
$this->assertEquals(json_decode($response, true), $actual, 'The response is json-decoded.');
46+
$this->assertApiResponse($response, $this->api->addWorklog('JRA-15', $time_spent), false);
4947
}
5048

5149
public static function addWorkLogWithoutCustomParamsDataProvider()
@@ -68,9 +66,11 @@ public function testAddWorklogWithCustomParams()
6866
$response
6967
);
7068

71-
$actual = $this->api->addWorklog('JRA-15', '12m', array('started' => $started));
72-
73-
$this->assertEquals(json_decode($response, true), $actual, 'The response is json-decoded.');
69+
$this->assertApiResponse(
70+
$response,
71+
$this->api->addWorklog('JRA-15', '12m', array('started' => $started)),
72+
false
73+
);
7474
}
7575

7676
public function testDeleteWorkLogWithoutCustomParams()
@@ -84,9 +84,7 @@ public function testDeleteWorkLogWithoutCustomParams()
8484
$response
8585
);
8686

87-
$actual = $this->api->deleteWorklog('JRA-15', 11256);
88-
89-
$this->assertEquals(json_decode($response, true), $actual, 'The response is json-decoded.');
87+
$this->assertApiResponse($response, $this->api->deleteWorklog('JRA-15', 11256), false);
9088
}
9189

9290
public function testDeleteWorkLogWithCustomParams()
@@ -100,9 +98,11 @@ public function testDeleteWorkLogWithCustomParams()
10098
$response
10199
);
102100

103-
$actual = $this->api->deleteWorklog('JRA-15', 11256, array('custom' => 'param'));
104-
105-
$this->assertEquals(json_decode($response, true), $actual, 'The response is json-decoded.');
101+
$this->assertApiResponse(
102+
$response,
103+
$this->api->deleteWorklog('JRA-15', 11256, array('custom' => 'param')),
104+
false
105+
);
106106
}
107107

108108
}

tests/Jira/ProjectRolesApiTest.php

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

24-
$actual = $this->api->getRoles($project_id);
25-
26-
$expected = json_decode($response, true);
27-
$this->assertEquals($expected, $actual);
24+
$this->assertApiResponse($response, $this->api->getRoles($project_id), false);
2825
}
2926

3027
public function testGetProjectRoleDetails()
@@ -40,10 +37,7 @@ public function testGetProjectRoleDetails()
4037
$response
4138
);
4239

43-
$actual = $this->api->getRoleDetails($project_id, $role_id);
44-
45-
$expected = json_decode($response, true);
46-
$this->assertEquals($expected, $actual);
40+
$this->assertApiResponse($response, $this->api->getRoleDetails($project_id, $role_id), false);
4741
}
4842

4943
}

tests/Jira/ProjectVersionsApiTest.php

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

24-
$this->assertEquals(
25-
json_decode($response, true),
26-
$this->api->getVersions($project_key)
27-
);
24+
$this->assertApiResponse($response, $this->api->getVersions($project_key), false);
2825
}
2926

3027
public function testCreateVersionWithoutCustomParams()

tests/Jira/ProjectsApiTest.php

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

36-
$this->assertEquals(
37-
json_decode($response, true),
38-
$this->api->getProject('TST')
39-
);
36+
$this->assertApiResponse($response, $this->api->getProject('TST'), false);
4037
}
4138

4239
public function testGetProjectComponents()
@@ -49,10 +46,7 @@ public function testGetProjectComponents()
4946
$response
5047
);
5148

52-
$this->assertEquals(
53-
json_decode($response, true),
54-
$this->api->getProjectComponents('TST')
55-
);
49+
$this->assertApiResponse($response, $this->api->getProjectComponents('TST'), false);
5650
}
5751

5852
public function testGetProjectIssueTypes()
@@ -65,10 +59,7 @@ public function testGetProjectIssueTypes()
6559
$response
6660
);
6761

68-
$this->assertEquals(
69-
json_decode($response, true),
70-
$this->api->getProjectIssueTypes('TST')
71-
);
62+
$this->assertApiResponse($response, $this->api->getProjectIssueTypes('TST'), false);
7263
}
7364

7465
}

0 commit comments

Comments
 (0)