Skip to content

Commit 034fda8

Browse files
committed
fix php version dependancy.
impl issue update.
1 parent e36ce44 commit 034fda8

File tree

4 files changed

+70
-9
lines changed

4 files changed

+70
-9
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"type": "library",
55
"keywords": ["jira", "jira-php", "jira-rest"],
66
"require": {
7+
"php": ">=5.3",
78
"netresearch/jsonmapper": "0.4.*",
89
"monolog/monolog": "~1.12"
910
},

src/JiraClient.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ public function exec($context, $post_data = null, $custom_request = null) {
102102
if (!is_null($post_data)) {
103103
// PUT REQUEST
104104
if (!is_null($custom_request) && $custom_request == "PUT") {
105-
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
105+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
106106
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
107107
}
108108
if (!is_null($custom_request) && $custom_request == "DELETE") {
109-
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
109+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
110110
}
111111
else {
112112
curl_setopt($ch, CURLOPT_POST, true);
@@ -173,11 +173,13 @@ public function upload($context, $upload_file) {
173173
'file' => '@' . realpath($upload_file)
174174
);
175175
*/
176-
$attachments = new \CURLFile(realpath($upload_file));
176+
$attachments = realpath($upload_file);
177+
$filename = basename($upload_file);
177178

178179
// send file
179180
curl_setopt($ch, CURLOPT_POST, true);
180-
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => $attachments));
181+
curl_setopt($ch, CURLOPT_POSTFIELDS,
182+
array('file' => '@' . $attachments . ';filename=' . $filename));
181183

182184
curl_setopt($ch, CURLOPT_USERPWD, "$this->username:$this->password");
183185

src/issue/IssueService.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,37 @@ public function addAttachments($issueIdOrKey, $filePath) {
7575

7676
return $issue;
7777
}
78+
79+
/**
80+
* update issue
81+
*
82+
* @param $issueKey Issue Key
83+
* @param $issueField object of Issue class
84+
*
85+
* @return created issue key
86+
*/
87+
public function update($issueKey, $issueField) {
88+
$issue = new Issue();
89+
90+
$issue->key = $issueKey;
91+
92+
// serilize only not null field.
93+
$issue->fields = array_filter((array) $issueField, function ($val) {
94+
return !is_null($val);
95+
});
96+
97+
$data = json_encode($issue);
98+
99+
$this->log->addInfo("Update Issue=\n" . $data );
100+
101+
$ret = $this->exec($this->uri . "/$issueIdOrKey/attachments", $data, "PUT");
102+
103+
$issue = $this->json_mapper->map(
104+
json_decode($ret), new Issue()
105+
);
106+
107+
return $issue;
108+
}
78109
}
79110

80111
?>

tests/IssueTest.php

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testIssue()
2828

2929
public function testCreateIssue()
3030
{
31-
$this->markTestIncomplete();
31+
//$this->markTestIncomplete();
3232
try {
3333
$issueField = new IssueField();
3434

@@ -40,8 +40,6 @@ public function testCreateIssue()
4040
->setDescription("Full description for issue")
4141
->addVersion(null, "1.0.1")
4242
->addVersion(null, "1.0.3")
43-
->addAttachment('screen_capture.png')
44-
->addAttachment('bug-description.pdf')
4543
;
4644

4745
$issueService = new IssueService();
@@ -50,20 +48,49 @@ public function testCreateIssue()
5048

5149
//If success, Returns a link to the created issue.
5250
print_r($ret);
51+
52+
$issueKey = $ret->{'key'};
53+
return $issueKey;
5354
} catch (JIRAException $e) {
5455
$this->assertTrue(FALSE, "Create Failed : " . $e->getMessage());
5556
}
5657
}
5758
//
5859

59-
public function testAddAttachment()
60+
/**
61+
* @depends testCreateIssue
62+
*
63+
*/
64+
public function testAddAttachment($issueKey)
6065
{
6166
//$this->markTestIncomplete();
6267
try {
6368

6469
$issueService = new IssueService();
6570

66-
$ret = $issueService->addAttachments("TEST-879", 'screen_capture.png');
71+
$ret = $issueService->addAttachments($issueKey, './src/../screen_capture.png');
72+
73+
print_r($ret);
74+
75+
return $issueKey;
76+
} catch (JIRAException $e) {
77+
$this->assertTrue(FALSE, "Attach Failed : " . $e->getMessage());
78+
}
79+
}
80+
81+
/**
82+
* @depends testAddAttachment
83+
*
84+
*/
85+
public function testUpdateIssue($issueKey)
86+
{
87+
//$this->markTestIncomplete();
88+
try {
89+
$issueField = new IssueField();
90+
91+
$issueService = new IssueService();
92+
93+
$ret = $issueService->update($issueKey, 'screen_capture.png');
6794

6895
print_r($ret);
6996
} catch (JIRAException $e) {

0 commit comments

Comments
 (0)