-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace JiraRestApi\Attachment; | ||
|
||
use JiraRestApi\Issue\Attachment; | ||
use JiraRestApi\JiraClient; | ||
|
||
/** | ||
* Class AttachmentService | ||
* | ||
* @package JiraRestApi\Group | ||
*/ | ||
class AttachmentService extends \JiraRestApi\JiraClient | ||
{ | ||
private $uri = '/attachment'; | ||
|
||
/** | ||
* Returns the meta-data for an attachment, including the URI of the actual attached file. | ||
* | ||
* @param $id | ||
* @return \JiraRestApi\Issue\Attachment | ||
* | ||
* @throws \JiraRestApi\JiraException | ||
* @throws \JsonMapper_Exception | ||
*/ | ||
public function get($id) | ||
{ | ||
$ret = $this->exec($this->uri.'/'.$id, null); | ||
|
||
$this->log->addInfo("Result=\n".$ret); | ||
|
||
return $this->json_mapper->map( | ||
json_decode($ret), new Attachment() | ||
); | ||
} | ||
|
||
/** | ||
* Remove an attachment from an issue. | ||
* | ||
* @param $id | ||
* @return string | ||
* @throws \JiraRestApi\JiraException | ||
*/ | ||
public function remove($id) | ||
{ | ||
$ret = $this->exec($this->uri.'/'.$id, null, 'DELETE'); | ||
|
||
$this->log->addInfo("Result=\n".$ret); | ||
|
||
return $ret; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
use JiraRestApi\Attachment\AttachmentService; | ||
use JiraRestApi\Issue\IssueService; | ||
use JiraRestApi\Issue\RemoteIssueLink; | ||
use JiraRestApi\JiraException; | ||
|
||
class AttachmentTest extends PHPUnit_Framework_TestCase | ||
{ | ||
public function testGetAttachment() | ||
{ | ||
$attachmentId = getenv("ID"); | ||
if ($attachmentId == FALSE) | ||
$attachmentId = 12622; | ||
|
||
try { | ||
$atts = new AttachmentService(); | ||
|
||
$att = $atts->get($attachmentId); | ||
|
||
return $attachmentId; | ||
} catch (JiraException $e) { | ||
$this->assertTrue(false, 'Create Failed : '.$e->getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function testRemoveAttachment() | ||
{ | ||
$attachmentId = 12622; | ||
try { | ||
$atts = new AttachmentService(); | ||
|
||
$atts->remove($attachmentId); | ||
|
||
$this->assertGreaterThan(0, count(1)); | ||
|
||
//$this->assertInstanceOf(RemoteIssueLink::class, $rils[0]); | ||
|
||
// return $issueKey; | ||
} catch (HTTPException $e) { | ||
$this->assertTrue(false, $e->getMessage()); | ||
} | ||
} | ||
|
||
|
||
} |