Skip to content

Commit 0b31bb3

Browse files
committed
Boards integration
1 parent 45987fd commit 0b31bb3

File tree

4 files changed

+277
-0
lines changed

4 files changed

+277
-0
lines changed

src/Board/Board.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
namespace JiraRestApi\Board;
4+
5+
use JiraRestApi\ClassSerialize;
6+
7+
class Board implements \JsonSerializable
8+
{
9+
10+
use ClassSerialize;
11+
12+
/** @var int */
13+
public $id;
14+
15+
/** @var string */
16+
public $self;
17+
18+
/** @var string */
19+
public $name;
20+
21+
/** @var string */
22+
public $type;
23+
24+
/**
25+
* Location [\JiraRestApi\Board\Location].
26+
*
27+
* @var \JiraRestApi\Board\Location
28+
*/
29+
public $location;
30+
31+
/**
32+
* Get board id.
33+
*/
34+
public function getId()
35+
{
36+
return $this->id;
37+
}
38+
39+
/**
40+
* Get board url.
41+
*/
42+
public function getSelf()
43+
{
44+
return $this->self;
45+
}
46+
47+
/**
48+
* Get board name.
49+
*/
50+
public function getName()
51+
{
52+
return $this->name;
53+
}
54+
55+
/**
56+
* Get board type.
57+
*/
58+
public function getType()
59+
{
60+
return $this->type;
61+
}
62+
63+
/**
64+
* Get location.
65+
*/
66+
public function getLocation()
67+
{
68+
return $this->location;
69+
}
70+
71+
public function jsonSerialize()
72+
{
73+
return array_filter(get_object_vars($this), function ($var) {
74+
return !is_null($var);
75+
});
76+
}
77+
78+
}

src/Board/BoardService.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace JiraRestApi\Board;
4+
5+
use JiraRestApi\Configuration\ConfigurationInterface;
6+
use JiraRestApi\Issue\Issue;
7+
8+
class BoardService extends \JiraRestApi\JiraClient
9+
{
10+
private $uri = '/board';
11+
12+
public function __construct(ConfigurationInterface $configuration = null, Logger $logger = null, $path = './')
13+
{
14+
parent::__construct($configuration, $logger, $path);
15+
$this->setAPIUri('/rest/agile/1.0');
16+
}
17+
18+
/**
19+
* get all project list.
20+
*
21+
* @param array $paramArray
22+
*
23+
* @throws \JiraRestApi\JiraException
24+
*
25+
* @return Project[] array of Project class
26+
*/
27+
public function getBoardList($paramArray = [])
28+
{
29+
$json = $this->exec($this->uri. $this->toHttpQueryParameter($paramArray), null);
30+
$boards = $this->json_mapper->mapArray(
31+
json_decode($json)->values, new \ArrayObject(), Board::class
32+
);
33+
return $boards;
34+
}
35+
36+
public function getBoard($id, $paramArray = []) {
37+
$json = $this->exec($this->uri . '/' . $id . $this->toHttpQueryParameter($paramArray), null);
38+
$board = $this->json_mapper->map(
39+
json_decode($json), new Board()
40+
);
41+
return $board;
42+
}
43+
44+
public function getBoardIssues($id, $paramArray = []) {
45+
$json = $this->exec($this->uri . '/' . $id . $this->toHttpQueryParameter($paramArray), null);
46+
$board = $this->json_mapper->mapArray(
47+
json_decode($json), new \ArrayObject(), Issue::class
48+
);
49+
return $board;
50+
}
51+
52+
}

src/Board/Location.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
namespace JiraRestApi\Board;
4+
5+
class Location implements \JsonSerializable {
6+
7+
/** @var int **/
8+
public $projectId;
9+
10+
/** @var string **/
11+
public $displayName;
12+
13+
/** @var string **/
14+
public $projectName;
15+
16+
/** @var string **/
17+
public $projectKey;
18+
19+
/** @var string **/
20+
public $projectTypeKey;
21+
22+
/** @var string **/
23+
public $avatarUri;
24+
25+
/** @var string **/
26+
public $name;
27+
28+
/**
29+
* Get project id.
30+
*/
31+
public function getProjectId() {
32+
return $this->projectId;
33+
}
34+
35+
/**
36+
* Get project id.
37+
*/
38+
public function getDisplayName() {
39+
return $this->displayName;
40+
}
41+
42+
/**
43+
* Get project name.
44+
*/
45+
public function getProjectName() {
46+
return $this->projectName;
47+
}
48+
49+
/**
50+
* Get project key.
51+
*/
52+
public function getProjectKey() {
53+
return $this->projectKey;
54+
}
55+
56+
/**
57+
* Get project type key.
58+
*/
59+
public function getProjectTypeKey() {
60+
return $this->projectTypeKey;
61+
}
62+
63+
/**
64+
* Get avatar uri.
65+
*/
66+
public function getAvatarUri() {
67+
return $this->avatarUri;
68+
}
69+
70+
/**
71+
* Get name.
72+
*/
73+
public function getName() {
74+
return $this->name;
75+
}
76+
77+
/**
78+
* {@inheritdoc}
79+
*/
80+
public function jsonSerialize()
81+
{
82+
return array_filter(get_object_vars($this), function ($var) {
83+
return !is_null($var);
84+
});
85+
}
86+
87+
}

tests/BoardTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
use JiraRestApi\Board\BoardService;
4+
use JiraRestApi\Board\Board;
5+
use JiraRestApi\Board\Location;
6+
use JiraRestApi\Issue\Issue;
7+
8+
/**
9+
* Test agile boards integration.
10+
*/
11+
class BoardTest extends PHPUnit_Framework_TestCase
12+
{
13+
14+
/**
15+
* Test we can obtain the board list.
16+
*/
17+
public function testGetBoards()
18+
{
19+
$board_service = new BoardService();
20+
21+
$board_list = $board_service->getBoardList();
22+
$this->assertInstanceOf(ArrayObject::class, $board_list, 'We receive a board list.');
23+
/** @var \JiraRestApi\Board\Board $first_board */
24+
$first_board = reset($board_list);
25+
$this->assertInstanceOf(Board::class, $first_board, 'Each element of the list is a Board instance.');
26+
27+
}
28+
29+
/**
30+
* Test we can obtain a single board.
31+
*/
32+
public function testGetBoard()
33+
{
34+
$board_service = new BoardService();
35+
36+
$board = $board_service->getBoard(42);
37+
38+
/** @var \JiraRestApi\Board\Board $board */
39+
$this->assertInstanceOf(Board::class, $board, 'We receive a board instance');
40+
$this->assertNotEmpty($board->getId(), 'Check board id.');
41+
$this->assertNotEmpty($board->getName(), 'Check board name.');
42+
$this->assertNotEmpty($board->getType(), 'Check board type.');
43+
$this->assertNotEmpty($board->getSelf(), 'Check board self.');
44+
$this->assertInstanceOf(Location::class, $board->getLocation(), 'Check board location.');
45+
46+
}
47+
48+
/**
49+
* Test we can obtain board issues.
50+
*/
51+
public function testGetBoardIssues()
52+
{
53+
$board_service = new BoardService();
54+
$board_issues = $board_service->getBoardIssues(42);
55+
$this->assertInstanceOf(ArrayObject::class, $board_issues, 'We receive a board issue list.');
56+
$first_issue = reset($board_issues);
57+
$this->assertInstanceOf(Issue::class, $first_issue);
58+
}
59+
60+
}

0 commit comments

Comments
 (0)