File tree Expand file tree Collapse file tree 2 files changed +101
-0
lines changed Expand file tree Collapse file tree 2 files changed +101
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace JiraRestApi \Attachment ;
4
+
5
+ use JiraRestApi \Issue \Attachment ;
6
+ use JiraRestApi \JiraClient ;
7
+
8
+ /**
9
+ * Class AttachmentService
10
+ *
11
+ * @package JiraRestApi\Group
12
+ */
13
+ class AttachmentService extends \JiraRestApi \JiraClient
14
+ {
15
+ private $ uri = '/attachment ' ;
16
+
17
+ /**
18
+ * Returns the meta-data for an attachment, including the URI of the actual attached file.
19
+ *
20
+ * @param $id
21
+ * @return \JiraRestApi\Issue\Attachment
22
+ *
23
+ * @throws \JiraRestApi\JiraException
24
+ * @throws \JsonMapper_Exception
25
+ */
26
+ public function get ($ id )
27
+ {
28
+ $ ret = $ this ->exec ($ this ->uri .'/ ' .$ id , null );
29
+
30
+ $ this ->log ->addInfo ("Result= \n" .$ ret );
31
+
32
+ return $ this ->json_mapper ->map (
33
+ json_decode ($ ret ), new Attachment ()
34
+ );
35
+ }
36
+
37
+ /**
38
+ * Remove an attachment from an issue.
39
+ *
40
+ * @param $id
41
+ * @return string
42
+ * @throws \JiraRestApi\JiraException
43
+ */
44
+ public function remove ($ id )
45
+ {
46
+ $ ret = $ this ->exec ($ this ->uri .'/ ' .$ id , null , 'DELETE ' );
47
+
48
+ $ this ->log ->addInfo ("Result= \n" .$ ret );
49
+
50
+ return $ ret ;
51
+ }
52
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use JiraRestApi \Attachment \AttachmentService ;
4
+ use JiraRestApi \Issue \IssueService ;
5
+ use JiraRestApi \Issue \RemoteIssueLink ;
6
+ use JiraRestApi \JiraException ;
7
+
8
+ class AttachmentTest extends PHPUnit_Framework_TestCase
9
+ {
10
+ public function testGetAttachment ()
11
+ {
12
+ $ attachmentId = getenv ("ID " );
13
+ if ($ attachmentId == FALSE )
14
+ $ attachmentId = 12622 ;
15
+
16
+ try {
17
+ $ atts = new AttachmentService ();
18
+
19
+ $ att = $ atts ->get ($ attachmentId );
20
+
21
+ return $ attachmentId ;
22
+ } catch (JiraException $ e ) {
23
+ $ this ->assertTrue (false , 'Create Failed : ' .$ e ->getMessage ());
24
+ }
25
+ }
26
+
27
+ /**
28
+ *
29
+ */
30
+ public function testRemoveAttachment ()
31
+ {
32
+ $ attachmentId = 12622 ;
33
+ try {
34
+ $ atts = new AttachmentService ();
35
+
36
+ $ atts ->remove ($ attachmentId );
37
+
38
+ $ this ->assertGreaterThan (0 , count (1 ));
39
+
40
+ //$this->assertInstanceOf(RemoteIssueLink::class, $rils[0]);
41
+
42
+ // return $issueKey;
43
+ } catch (HTTPException $ e ) {
44
+ $ this ->assertTrue (false , $ e ->getMessage ());
45
+ }
46
+ }
47
+
48
+
49
+ }
You can’t perform that action at this time.
0 commit comments