Skip to content

Commit

Permalink
- update doc param in AttachmentService(#41)
Browse files Browse the repository at this point in the history
- update example
  • Loading branch information
lesstif committed Feb 12, 2023
1 parent c565ab9 commit 6dbd456
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 22 deletions.
19 changes: 10 additions & 9 deletions src/Attachment/AttachmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace JiraCloud\Attachment;

use JiraCloud\Issue\Attachment;
use JiraCloud\JiraException;

/**
* Class AttachmentService.
Expand All @@ -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);

Expand Down Expand Up @@ -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');

Expand Down
27 changes: 18 additions & 9 deletions tests/AttachmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}


Expand Down
26 changes: 24 additions & 2 deletions tests/ProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions tests/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit 6dbd456

Please sign in to comment.