Skip to content

Commit 6dbd456

Browse files
committed
- update doc param in AttachmentService(#41)
- update example
1 parent c565ab9 commit 6dbd456

4 files changed

Lines changed: 56 additions & 22 deletions

File tree

src/Attachment/AttachmentService.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace JiraCloud\Attachment;
44

55
use JiraCloud\Issue\Attachment;
6+
use JiraCloud\JiraException;
67

78
/**
89
* Class AttachmentService.
@@ -14,18 +15,18 @@ class AttachmentService extends \JiraCloud\JiraClient
1415
/**
1516
* Returns the meta-data for an attachment, including the URI of the actual attached file.
1617
*
17-
* @param string|int $id attachment Id
18+
* @param int|string $id attachment Id
1819
* @outDir string downloads the content and store into outDir
1920
* @overwrite boolean determines whether to overwrite the file if it already exists.
2021
* @mode int outDir creation mode.
2122
* @recursive boolean Allows the creation of nested directories specified in the pathname.
2223
*
23-
*@throws \JsonMapper_Exception
24-
* @throws \JiraCloud\JiraException
24+
*@return Attachment
25+
*@throws JiraException
2526
*
26-
* @return \JiraCloud\ADF\Attachment
27+
* @throws \JsonMapper_Exception
2728
*/
28-
public function get($id, $outDir = null, $overwrite = false, $mode = 0777, $recursive = true)
29+
public function get(int|string $id, string $outDir = null, bool $overwrite = false, int $mode = 0777, bool $recursive = true) : Attachment
2930
{
3031
$ret = $this->exec($this->uri.$id, null);
3132

@@ -60,13 +61,13 @@ public function get($id, $outDir = null, $overwrite = false, $mode = 0777, $recu
6061
/**
6162
* Remove an attachment from an issue.
6263
*
63-
* @param string|int $id attachment id
64-
*
65-
* @throws \JiraCloud\JiraException
64+
* @param int|string $id attachment id
6665
*
6766
* @return string
67+
*@throws JiraException
68+
*
6869
*/
69-
public function remove($id)
70+
public function remove(int|string $id) : string
7071
{
7172
$ret = $this->exec($this->uri.$id, null, 'DELETE');
7273

tests/AttachmentTest.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22

33
namespace JiraCloud\Test;
44

5+
use HttpException;
56
use PHPUnit\Framework\TestCase;
67
use JiraCloud\Attachment\AttachmentService;
78
use JiraCloud\JiraException;
89

910
class AttachmentTest extends TestCase
1011
{
11-
public function testGetAttachment()
12+
/**
13+
* @test
14+
* @throws \JsonMapper_Exception
15+
*/
16+
public function get_attachment_by_id() : string
1217
{
13-
$attachmentId = 12643;
18+
$attachmentId = '12643';
1419

1520
try {
1621
$atts = new AttachmentService();
@@ -19,27 +24,31 @@ public function testGetAttachment()
1924

2025
dump($att);
2126

22-
return $attachmentId;
2327
} catch (JiraException $e) {
24-
$this->assertTrue(false, 'Create Failed : '.$e->getMessage());
28+
$this->fail('Create Failed : '.$e->getMessage());
2529
}
30+
31+
return $attachmentId;
2632
}
2733

2834
/**
29-
* @depends testGetAttachment
35+
* @test
36+
* @depends get_attachment_by_id
3037
*/
31-
public function testRemoveAttachment($attachmentId)
38+
public function remove_attachment(string $attachmentId) : string
3239
{
3340
try {
3441
$atts = new AttachmentService();
3542

3643
$atts->remove($attachmentId);
3744

38-
$this->assertGreaterThan(0, count(1));
45+
$this->assertGreaterThan(0, 1);
3946

40-
} catch (HTTPException $e) {
41-
$this->assertTrue(false, $e->getMessage());
47+
} catch (JiraException $e) {
48+
$this->fail($e->getMessage());
4249
}
50+
51+
return $attachmentId;
4352
}
4453

4554

tests/ProjectTest.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function get_project_version(string $projKey) : string
150150

151151
$prjs = $proj->getVersions($projKey);
152152

153-
$this->assertNull($prjs);
153+
$this->assertIsObject($prjs);
154154
$this->assertTrue($prjs instanceof \ArrayObject);
155155
$this->assertLessThan($prjs->count(), 2);
156156

@@ -163,7 +163,29 @@ public function get_project_version(string $projKey) : string
163163

164164
/**
165165
* @test
166-
* @depends get_project_accessible
166+
* @depends get_project_version
167+
*/
168+
public function get_project_assignable(string $projKey) : string
169+
{
170+
try {
171+
$proj = new ProjectService();
172+
173+
$reporters = $proj->getAssignable($projKey);
174+
175+
$this->assertIsArray($reporters);
176+
//$this->assertTrue($reporters instanceof \ArrayObject);
177+
$this->assertLessThan(count($reporters), 2);
178+
179+
} catch (\Exception $e) {
180+
$this->fail('get_project_version ' . $e->getMessage());
181+
}
182+
183+
return $projKey;
184+
}
185+
186+
/**
187+
* @test
188+
* @depends get_project_assignable
167189
*
168190
*/
169191
public function get_unknown_project_type_expect_to_JiraException(string $projKey) : string

tests/VersionTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class VersionTest extends TestCase
2121
*/
2222
public function create_version() :string
2323
{
24-
$versionName = '2.3.5';
24+
$versionName = '2.3.4';
2525
try {
2626
$projectService = new ProjectService();
2727
$project = $projectService->get($this->project);
@@ -55,6 +55,7 @@ public function create_version() :string
5555
*/
5656
public function update_project_version(string $versionName) : string
5757
{
58+
$newVersionName = null;
5859
try {
5960
$versionService = new VersionService();
6061
$projectService = new ProjectService();
@@ -75,10 +76,11 @@ public function update_project_version(string $versionName) : string
7576

7677
$this->assertEquals($res->name, $ver->name);
7778

78-
return $newVersionName;
7979
} catch (JiraException $e) {
8080
print("Error Occurred! " . $e->getMessage());
8181
}
82+
83+
return $newVersionName;
8284
}
8385

8486
/**

0 commit comments

Comments
 (0)