From 6dbd4564e2fb6fa33ab6e7eaae538e53d8ee3455 Mon Sep 17 00:00:00 2001 From: KwangSeob Jeong Date: Sun, 12 Feb 2023 18:09:08 +0900 Subject: [PATCH] - update doc param in AttachmentService(#41) - update example --- src/Attachment/AttachmentService.php | 19 ++++++++++--------- tests/AttachmentTest.php | 27 ++++++++++++++++++--------- tests/ProjectTest.php | 26 ++++++++++++++++++++++++-- tests/VersionTest.php | 6 ++++-- 4 files changed, 56 insertions(+), 22 deletions(-) diff --git a/src/Attachment/AttachmentService.php b/src/Attachment/AttachmentService.php index e813cec..070ab68 100644 --- a/src/Attachment/AttachmentService.php +++ b/src/Attachment/AttachmentService.php @@ -3,6 +3,7 @@ namespace JiraCloud\Attachment; use JiraCloud\Issue\Attachment; +use JiraCloud\JiraException; /** * Class AttachmentService. @@ -14,18 +15,18 @@ class AttachmentService extends \JiraCloud\JiraClient /** * Returns the meta-data for an attachment, including the URI of the actual attached file. * - * @param string|int $id attachment Id + * @param int|string $id attachment Id * @outDir string downloads the content and store into outDir * @overwrite boolean determines whether to overwrite the file if it already exists. * @mode int outDir creation mode. * @recursive boolean Allows the creation of nested directories specified in the pathname. * - *@throws \JsonMapper_Exception - * @throws \JiraCloud\JiraException + *@return Attachment + *@throws JiraException * - * @return \JiraCloud\ADF\Attachment + * @throws \JsonMapper_Exception */ - public function get($id, $outDir = null, $overwrite = false, $mode = 0777, $recursive = true) + public function get(int|string $id, string $outDir = null, bool $overwrite = false, int $mode = 0777, bool $recursive = true) : Attachment { $ret = $this->exec($this->uri.$id, null); @@ -60,13 +61,13 @@ public function get($id, $outDir = null, $overwrite = false, $mode = 0777, $recu /** * Remove an attachment from an issue. * - * @param string|int $id attachment id - * - * @throws \JiraCloud\JiraException + * @param int|string $id attachment id * * @return string + *@throws JiraException + * */ - public function remove($id) + public function remove(int|string $id) : string { $ret = $this->exec($this->uri.$id, null, 'DELETE'); diff --git a/tests/AttachmentTest.php b/tests/AttachmentTest.php index 439c493..e0a14e9 100644 --- a/tests/AttachmentTest.php +++ b/tests/AttachmentTest.php @@ -2,15 +2,20 @@ namespace JiraCloud\Test; +use HttpException; use PHPUnit\Framework\TestCase; use JiraCloud\Attachment\AttachmentService; use JiraCloud\JiraException; class AttachmentTest extends TestCase { - public function testGetAttachment() + /** + * @test + * @throws \JsonMapper_Exception + */ + public function get_attachment_by_id() : string { - $attachmentId = 12643; + $attachmentId = '12643'; try { $atts = new AttachmentService(); @@ -19,27 +24,31 @@ public function testGetAttachment() dump($att); - return $attachmentId; } catch (JiraException $e) { - $this->assertTrue(false, 'Create Failed : '.$e->getMessage()); + $this->fail('Create Failed : '.$e->getMessage()); } + + return $attachmentId; } /** - * @depends testGetAttachment + * @test + * @depends get_attachment_by_id */ - public function testRemoveAttachment($attachmentId) + public function remove_attachment(string $attachmentId) : string { try { $atts = new AttachmentService(); $atts->remove($attachmentId); - $this->assertGreaterThan(0, count(1)); + $this->assertGreaterThan(0, 1); - } catch (HTTPException $e) { - $this->assertTrue(false, $e->getMessage()); + } catch (JiraException $e) { + $this->fail($e->getMessage()); } + + return $attachmentId; } diff --git a/tests/ProjectTest.php b/tests/ProjectTest.php index cd93df4..c48456c 100644 --- a/tests/ProjectTest.php +++ b/tests/ProjectTest.php @@ -150,7 +150,7 @@ public function get_project_version(string $projKey) : string $prjs = $proj->getVersions($projKey); - $this->assertNull($prjs); + $this->assertIsObject($prjs); $this->assertTrue($prjs instanceof \ArrayObject); $this->assertLessThan($prjs->count(), 2); @@ -163,7 +163,29 @@ public function get_project_version(string $projKey) : string /** * @test - * @depends get_project_accessible + * @depends get_project_version + */ + public function get_project_assignable(string $projKey) : string + { + try { + $proj = new ProjectService(); + + $reporters = $proj->getAssignable($projKey); + + $this->assertIsArray($reporters); + //$this->assertTrue($reporters instanceof \ArrayObject); + $this->assertLessThan(count($reporters), 2); + + } catch (\Exception $e) { + $this->fail('get_project_version ' . $e->getMessage()); + } + + return $projKey; + } + + /** + * @test + * @depends get_project_assignable * */ public function get_unknown_project_type_expect_to_JiraException(string $projKey) : string diff --git a/tests/VersionTest.php b/tests/VersionTest.php index 5f52b48..a2ac21b 100644 --- a/tests/VersionTest.php +++ b/tests/VersionTest.php @@ -21,7 +21,7 @@ class VersionTest extends TestCase */ public function create_version() :string { - $versionName = '2.3.5'; + $versionName = '2.3.4'; try { $projectService = new ProjectService(); $project = $projectService->get($this->project); @@ -55,6 +55,7 @@ public function create_version() :string */ public function update_project_version(string $versionName) : string { + $newVersionName = null; try { $versionService = new VersionService(); $projectService = new ProjectService(); @@ -75,10 +76,11 @@ public function update_project_version(string $versionName) : string $this->assertEquals($res->name, $ver->name); - return $newVersionName; } catch (JiraException $e) { print("Error Occurred! " . $e->getMessage()); } + + return $newVersionName; } /**