Skip to content

Commit 3701b07

Browse files
committed
Added shorthand releaseVersion() and added tests
1 parent 4437dae commit 3701b07

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

src/Jira/Api.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ public function getRoleDetails($projectKey, $roleId)
222222
* @param $issuetypeIds array Combined with issuetypeNames, lists the issue types with which to filter the results.
223223
* If null, all issue types are returned. Specifiying an issue type that does not exist is
224224
* not an error.
225+
*
225226
* @param $issuetypeNames array Combined with issuetypeIds, lists the issue types with which to filter the results.
226227
* If null, all issue types are returned. This parameter can be specified multiple times,
227228
* but is NOT interpreted as a comma-separated list. Specifiying an issue type that does
@@ -487,6 +488,8 @@ public function createVersion($projectId, $name, $options = array())
487488

488489
/**
489490
* Update JIRA Version
491+
*
492+
* https://docs.atlassian.com/jira/REST/latest/#api/2/version-updateVersion
490493
*
491494
* @param int $versionId Version identifier
492495
* @param array $params Key->Value list to update the version with.
@@ -497,6 +500,32 @@ public function updateVersion($versionId, $params = array()) {
497500
return $this->api(self::REQUEST_PUT, sprintf('/rest/api/2/version/%d', $versionId), $params);
498501
}
499502

503+
/**
504+
* Shorthand to mark a version as Released
505+
*
506+
* @param int $versionId Version identifier
507+
* @param string|null $releaseDate Date in Y-m-d format. Defaults to today
508+
* @param array $params Optionally extra parameters.
509+
*
510+
* @return Result|false
511+
*/
512+
public function releaseVersion($versionId, $releaseDate = null, $params = array()) {
513+
if(!$releaseDate) {
514+
$releaseDate = date("Y-m-d");
515+
}
516+
517+
// TODO Not entirely sure what to do yet with userReleaseDate
518+
$params = array_merge(
519+
array(
520+
"releaseDate" => $releaseDate,
521+
'released' => true
522+
),
523+
$params
524+
);
525+
526+
return $this->updateVersion($versionId, $params);
527+
}
528+
500529
/**
501530
* Create JIRA Attachment
502531
*

tests/Jira/ApiTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,51 @@ public function testUpdateVersion()
4747

4848
$api->updateVersion(111000, $params);
4949
}
50+
51+
/**
52+
* Tests that the releaseVersion call constructs the correct api call
53+
*/
54+
public function testReleaseVersion()
55+
{
56+
$params = [
57+
"released" => true,
58+
"releaseDate" => date("Y-m-d"),
59+
];
60+
61+
// Stub the api method and keep the rest intact
62+
/** @var Api|\PHPUnit_Framework_MockObject_MockObject $api */
63+
$api = $this->getMockBuilder(Api::class)->setMethods(["api"])->disableOriginalConstructor()->getMock();
64+
$api->expects($this->once())->method("api")->with(
65+
$this->equalTo(Api::REQUEST_PUT),
66+
$this->equalTo("/rest/api/2/version/111000"),
67+
$this->equalTo($params)
68+
);
69+
70+
$api->releaseVersion(111000);
71+
}
72+
73+
/**
74+
* Tests that the releaseVersion call constructs the correct api call with overriden release data and params
75+
*/
76+
public function testReleaseVersionAdvanced()
77+
{
78+
$releaseDate = "2010-07-06";
79+
80+
$params = [
81+
"released" => true,
82+
"releaseDate" => $releaseDate,
83+
"test" => "extra"
84+
];
85+
86+
// Stub the api method and keep the rest intact
87+
/** @var Api|\PHPUnit_Framework_MockObject_MockObject $api */
88+
$api = $this->getMockBuilder(Api::class)->setMethods(["api"])->disableOriginalConstructor()->getMock();
89+
$api->expects($this->once())->method("api")->with(
90+
$this->equalTo(Api::REQUEST_PUT),
91+
$this->equalTo("/rest/api/2/version/111000"),
92+
$this->equalTo($params)
93+
);
94+
95+
$api->releaseVersion(111000, $releaseDate, ["test" => "extra"]);
96+
}
5097
}

0 commit comments

Comments
 (0)