Skip to content

Commit f8583f5

Browse files
add partial statuses support (#345)
* add partial statuses support * fix cs Co-authored-by: Alexey Mogilyovkin <[email protected]>
1 parent bbba47e commit f8583f5

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

src/Status/Status.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace JiraRestApi\Status;
4+
5+
6+
class Status implements \JsonSerializable
7+
{
8+
/** @var int */
9+
public $id;
10+
11+
/** @var string */
12+
public $name;
13+
14+
/** @var string */
15+
public $description;
16+
17+
public function jsonSerialize()
18+
{
19+
return array_filter(get_object_vars($this));
20+
}
21+
}

src/Status/StatusService.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace JiraRestApi\Status;
4+
5+
6+
use JiraRestApi\JiraException;
7+
use JsonMapper_Exception;
8+
9+
class StatusService extends \JiraRestApi\JiraClient
10+
{
11+
private $uri = '/status';
12+
13+
/**
14+
* get all statuses
15+
* @throws JiraException
16+
* @throws JsonMapper_Exception
17+
*
18+
* @return Status[] array of Project class
19+
*/
20+
public function getAll()
21+
{
22+
if ($this->isRestApiV3()) {
23+
throw new JiraException('V3 is currently not supported');
24+
}
25+
26+
else {
27+
$statusObject = new Status();
28+
}
29+
30+
$ret = $this->exec($this->uri.'/', null);
31+
$this->log->info("Result=\n".$ret);
32+
33+
34+
return $this->json_mapper->mapArray(
35+
json_decode($ret, false),
36+
new \ArrayObject(),
37+
'\JiraRestApi\Status\status'
38+
);
39+
}
40+
}

tests/StatusTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
use JiraRestApi\Status\StatusService;
4+
5+
class StatusTest extends PHPUnit_Framework_TestCase
6+
{
7+
public function testStatus()
8+
{
9+
$statusService = new StatusService();
10+
$statuses = $statusService->getAll();
11+
foreach ($statuses as $s) {
12+
$this->assertTrue($s instanceof JiraRestApi\Status\Status);
13+
$this->assertTrue(!empty($s->name) > 0);
14+
$this->assertTrue(!empty($s->id));
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)