Skip to content

Commit 798023e

Browse files
committed
Don't specify optional API call parameters, when "Api::createRemoteLink" was called without them
1 parent 236316d commit 798023e

File tree

3 files changed

+114
-9
lines changed

3 files changed

+114
-9
lines changed

src/Jira/Api.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -723,27 +723,25 @@ public function createAttachment($issue_key, $filename, $name = null)
723723
* @param string $global_id Global ID.
724724
* @param array $application Application.
725725
*
726-
* @return array|false
726+
* @return array
727727
* @since 2.0.0
728+
* @link https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issue-remote-links/#api-rest-api-2-issue-issueidorkey-remotelink-post
728729
*/
729730
public function createRemoteLink(
730731
$issue_key,
731-
array $object = array(),
732+
array $object,
732733
$relationship = null,
733734
$global_id = null,
734735
array $application = null
735736
) {
736-
$options = array(
737+
$params = array_filter(array(
737738
'globalId' => $global_id,
738739
'relationship' => $relationship,
739740
'object' => $object,
740-
);
741-
742-
if ( $application !== null ) {
743-
$options['application'] = $application;
744-
}
741+
'application' => $application,
742+
));
745743

746-
return $this->api(self::REQUEST_POST, sprintf('/rest/api/2/issue/%s/remotelink', $issue_key), $options, true);
744+
return $this->api(self::REQUEST_POST, sprintf('/rest/api/2/issue/%s/remotelink', $issue_key), $params, true);
747745
}
748746

749747
/**

tests/Jira/ApiTest.php

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,109 @@ public function testReleaseVersionParameterMerging()
152152
$this->assertFalse($this->api->releaseVersion(111000, $release_date, array('test' => 'extra')));
153153
}
154154

155+
/**
156+
* @dataProvider createRemoteLinkDataProvider
157+
*/
158+
public function testCreateRemoteLink(array $method_params, array $expected_api_params)
159+
{
160+
$response = file_get_contents(__DIR__ . '/resources/api_create_remote_link.json');
161+
162+
$this->expectClientCall(
163+
Api::REQUEST_POST,
164+
'/rest/api/2/issue/JRE-123/remotelink',
165+
$expected_api_params,
166+
$response
167+
);
168+
169+
$expected = json_decode($response, true);
170+
$actual = call_user_func_array(array($this->api, 'createRemoteLink'), $method_params);
171+
172+
if ( $actual !== false ) {
173+
$this->assertEquals($expected, $actual);
174+
}
175+
}
176+
177+
public static function createRemoteLinkDataProvider()
178+
{
179+
return array(
180+
'object only' => array(
181+
array(
182+
'JRE-123',
183+
array(
184+
'title' => 'TSTSUP-111',
185+
'url' => 'http://www.mycompany.com/support?id=1',
186+
),
187+
),
188+
array(
189+
'object' => array(
190+
'title' => 'TSTSUP-111',
191+
'url' => 'http://www.mycompany.com/support?id=1',
192+
),
193+
),
194+
),
195+
'object+relationship' => array(
196+
array(
197+
'JRE-123',
198+
array(
199+
'title' => 'TSTSUP-111',
200+
'url' => 'http://www.mycompany.com/support?id=1',
201+
),
202+
'blocked by',
203+
),
204+
array(
205+
'relationship' => 'blocked by',
206+
'object' => array(
207+
'title' => 'TSTSUP-111',
208+
'url' => 'http://www.mycompany.com/support?id=1',
209+
),
210+
),
211+
),
212+
'object+global_id' => array(
213+
array(
214+
'JRE-123',
215+
array(
216+
'title' => 'TSTSUP-111',
217+
'url' => 'http://www.mycompany.com/support?id=1',
218+
),
219+
null,
220+
'global-id',
221+
),
222+
array(
223+
'globalId' => 'global-id',
224+
'object' => array(
225+
'title' => 'TSTSUP-111',
226+
'url' => 'http://www.mycompany.com/support?id=1',
227+
),
228+
),
229+
),
230+
'object+application' => array(
231+
array(
232+
'JRE-123',
233+
array(
234+
'title' => 'TSTSUP-111',
235+
'url' => 'http://www.mycompany.com/support?id=1',
236+
),
237+
null,
238+
null,
239+
array(
240+
'name' => 'My Acme Tracker',
241+
'type' => 'com.acme.tracker',
242+
),
243+
),
244+
array(
245+
'object' => array(
246+
'title' => 'TSTSUP-111',
247+
'url' => 'http://www.mycompany.com/support?id=1',
248+
),
249+
'application' => array(
250+
'name' => 'My Acme Tracker',
251+
'type' => 'com.acme.tracker',
252+
),
253+
),
254+
),
255+
);
256+
}
257+
155258
public function testFindVersionByName()
156259
{
157260
$project_key = 'POR';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"id": 17095,
3+
"self": "https://test.atlassian.net/rest/api/2/issue/JRE-123/remotelink/17095"
4+
}

0 commit comments

Comments
 (0)