Skip to content

Commit d5d263c

Browse files
authored
Merge pull request #228 from mistermoper/fb-boards
#227 | Boards integration
2 parents 45987fd + 41a5734 commit d5d263c

File tree

4 files changed

+286
-0
lines changed

4 files changed

+286
-0
lines changed

src/Board/Board.php

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

src/Board/BoardService.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
34+
return $boards;
35+
}
36+
37+
public function getBoard($id, $paramArray = [])
38+
{
39+
$json = $this->exec($this->uri.'/'.$id.$this->toHttpQueryParameter($paramArray), null);
40+
$board = $this->json_mapper->map(
41+
json_decode($json), new Board()
42+
);
43+
44+
return $board;
45+
}
46+
47+
public function getBoardIssues($id, $paramArray = [])
48+
{
49+
$json = $this->exec($this->uri.'/'.$id.'/issue'.$this->toHttpQueryParameter($paramArray), null);
50+
$board = $this->json_mapper->mapArray(
51+
json_decode($json)->issues, new \ArrayObject(), Issue::class
52+
);
53+
54+
return $board;
55+
}
56+
}

src/Board/Location.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
{
33+
return $this->projectId;
34+
}
35+
36+
/**
37+
* Get project id.
38+
*/
39+
public function getDisplayName()
40+
{
41+
return $this->displayName;
42+
}
43+
44+
/**
45+
* Get project name.
46+
*/
47+
public function getProjectName()
48+
{
49+
return $this->projectName;
50+
}
51+
52+
/**
53+
* Get project key.
54+
*/
55+
public function getProjectKey()
56+
{
57+
return $this->projectKey;
58+
}
59+
60+
/**
61+
* Get project type key.
62+
*/
63+
public function getProjectTypeKey()
64+
{
65+
return $this->projectTypeKey;
66+
}
67+
68+
/**
69+
* Get avatar uri.
70+
*/
71+
public function getAvatarUri()
72+
{
73+
return $this->avatarUri;
74+
}
75+
76+
/**
77+
* Get name.
78+
*/
79+
public function getName()
80+
{
81+
return $this->name;
82+
}
83+
84+
/**
85+
* {@inheritdoc}
86+
*/
87+
public function jsonSerialize()
88+
{
89+
return array_filter(get_object_vars($this), function ($var) {
90+
return !is_null($var);
91+
});
92+
}
93+
}

tests/BoardTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
$this->assertNotEmpty($first_issue->id);
59+
}
60+
61+
}

0 commit comments

Comments
 (0)