Skip to content

Commit

Permalink
working..
Browse files Browse the repository at this point in the history
  • Loading branch information
lesstif committed Jun 2, 2018
1 parent 653267c commit 8885d65
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/Attachment/AttachmentService.php
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;
}
}
49 changes: 49 additions & 0 deletions tests/AttachmentTest.php
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());
}
}


}

0 comments on commit 8885d65

Please sign in to comment.