Skip to content

Commit cf85b77

Browse files
author
KwangSeob Jeong
committed
fixed json mapping error.
added json test data & unit test.
1 parent d901314 commit cf85b77

File tree

8 files changed

+177
-11
lines changed

8 files changed

+177
-11
lines changed

src/Issue/PaginatedWorklog.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class PaginatedWorklog
2727
public $total;
2828

2929
/**
30-
* @var Worklog[]|array Worklog
30+
* @var \JiraRestApi\Issue\Worklog[] Worklog
3131
*/
3232
public $worklogs;
3333

@@ -80,15 +80,15 @@ public function setTotal($total)
8080
}
8181

8282
/**
83-
* @return Worklog[]|array Worklogs
83+
* @return \JiraRestApi\Issue\Worklog[] Worklogs
8484
*/
8585
public function getWorklogs()
8686
{
8787
return $this->worklogs;
8888
}
8989

9090
/**
91-
* @param Worklog[]|array $worklogs
91+
* @param \JiraRestApi\Issue\Worklog[] $worklogs
9292
*/
9393
public function setWorklogs($worklogs)
9494
{

src/Issue/Reporter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Reporter implements \JsonSerializable
1717
/** @var string */
1818
public $emailAddress;
1919

20-
/** @var string */
20+
/** @var array|null */
2121
public $avatarUrls;
2222

2323
/** @var string */

src/Project/Project.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,23 @@ class Project
7171
/**
7272
* ComponentList [\JiraRestApi\Project\Component].
7373
*
74-
* @var Component[]
74+
* @var \JiraRestApi\Project\Component[]
7575
*/
7676
public $components;
7777

7878
/**
7979
* IssueTypeList [\JiraRestApi\Issue\IssueType].
8080
*
81-
* @var IssueType[]
81+
* @var \JiraRestApi\Issue\IssueType[]
8282
*/
8383
public $issueTypes;
8484

85-
/** @var string */
85+
/** @var string|null */
8686
public $assigneeType;
8787

88-
/** @var array */
88+
/** @var array|null */
8989
public $versions;
9090

91-
/** @var array */
91+
/** @var array|null */
9292
public $roles;
9393
}

src/Version/VersionService.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
namespace JiraRestApi\Version;
4+
5+
use JiraRestApi\Issue\IssueType;
6+
use JiraRestApi\Issue\Reporter;
7+
use JiraRestApi\Issue\Version;
8+
use JiraRestApi\JiraException;
9+
use JiraRestApi\Project\ProjectService;
10+
11+
class VersionService extends \JiraRestApi\JiraClient
12+
{
13+
private $uri = '/version';
14+
15+
/**
16+
* create version
17+
*
18+
* @see https://docs.atlassian.com/jira/REST/server/#api/2/version-createVersion
19+
*
20+
*/
21+
public function create($version)
22+
{
23+
throw new JiraException("create version not yet implemented");
24+
}
25+
26+
/**
27+
* Modify a version's sequence within a project.
28+
*
29+
* @param $version
30+
* @throws JiraException
31+
*/
32+
public function move($version)
33+
{
34+
throw new JiraException("move version not yet implemented");
35+
}
36+
37+
/**
38+
* get project version
39+
*
40+
* @param $id version id
41+
*
42+
* @return Version
43+
*
44+
* @see ProjectService::getVersions()
45+
*/
46+
public function get($id)
47+
{
48+
$ret = $this->exec($this->uri.'/'.$id);
49+
50+
$this->log->addInfo('Result='.$ret);
51+
52+
$json = json_decode($ret);
53+
$results = array_map(function ($elem) {
54+
return $this->json_mapper->map($elem, new ProjectType());
55+
}, $json);
56+
57+
return $results;
58+
}
59+
60+
public function update($ver)
61+
{
62+
throw new JiraException("update version not yet implemented");
63+
}
64+
65+
public function delete($ver)
66+
{
67+
throw new JiraException("delete version not yet implemented");
68+
}
69+
70+
public function merge($ver)
71+
{
72+
throw new JiraException("merge version not yet implemented");
73+
}
74+
75+
76+
/**
77+
* Returns a bean containing the number of fixed in and affected issues for the given version.
78+
*
79+
* @param $id int version id
80+
*
81+
* @throws JiraException
82+
*
83+
* @see https://docs.atlassian.com/jira/REST/server/#api/2/version-getVersionRelatedIssues
84+
*/
85+
public function getRelatedIssues($id)
86+
{
87+
throw new JiraException("get version Related Issues not yet implemented");
88+
}
89+
}

test-data/comment.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"self": "https://jira.example.com/rest/api/2/issue/13332/comment/12312",
3+
"id": "12312",
4+
"author": {
5+
"self": "https://jira.example.com/rest/api/2/user?username=lesstif",
6+
"name": "John Doe",
7+
"key": "lesstif",
8+
"emailAddress": "[email protected]",
9+
"avatarUrls": {
10+
"48x48": "https://jira.example.com/secure/useravatar?avatarId=10122",
11+
"24x24": "https://jira.example.com/secure/useravatar?size=small&avatarId=10122",
12+
"16x16": "https://jira.example.com/secure/useravatar?size=xsmall&avatarId=10122",
13+
"32x32": "https://jira.example.com/secure/useravatar?size=medium&avatarId=10122"
14+
},
15+
"displayName": "John Doe",
16+
"active": true,
17+
"timeZone": "ROK"
18+
},
19+
"body": "Adds a new comment to an issue.\\r\\n* Bullet 1\\r\\n* Bullet 2\\r\\n** sub Bullet 1\\r\\n** sub Bullet 2",
20+
"updateAuthor": {
21+
"self": "https://jira.example.com/rest/api/2/user?username=lesstif",
22+
"name": "KwangSeob Jeong",
23+
"key": "lesstif",
24+
"emailAddress": "[email protected]",
25+
"avatarUrls": {
26+
"48x48": "https://jira.example.com/secure/useravatar?avatarId=10122",
27+
"24x24": "https://jira.example.com/secure/useravatar?size=small&avatarId=10122",
28+
"16x16": "https://jira.example.com/secure/useravatar?size=xsmall&avatarId=10122",
29+
"32x32": "https://jira.example.com/secure/useravatar?size=medium&avatarId=10122"
30+
},
31+
"displayName": "정광섭",
32+
"active": true,
33+
"timeZone": "ROK"
34+
},
35+
"created": "2017-12-20T09:00:05.752+0900",
36+
"updated": "2017-12-20T09:00:05.752+0900",
37+
"visibility": {
38+
"type": "role",
39+
"value": "Users"
40+
}
41+
}

tests/MapperTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use JiraRestApi\Issue\Comment;
4+
use \Mockery as m;
5+
6+
class MapperTest extends PHPUnit_Framework_TestCase
7+
{
8+
/** @var JsonMapper */
9+
public $mapper;
10+
11+
public function setUp()
12+
{
13+
$this->mapper = new JsonMapper();
14+
}
15+
16+
public function tearDown()
17+
{
18+
$this->mapper = null;
19+
m::close();
20+
}
21+
22+
public function testComment()
23+
{
24+
$ret = file_get_contents('test-data/comment.json');
25+
26+
$comment = $this->mapper->map(
27+
json_decode($ret), new Comment()
28+
);
29+
30+
$this->assertInstanceOf(Comment::class, $comment);
31+
32+
$this->assertEquals('[email protected]', $comment->author->emailAddress);
33+
$this->assertEquals('KwangSeob Jeong', $comment->updateAuthor->name);
34+
}
35+
}

tests/SubTaskTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function testCreateSubTask()
2121
->setDescription('Subtask - Full description for issue')
2222
->addVersion('1.0.1')
2323
->addVersion('1.0.3')
24-
->setParent($this->issueKey);
24+
->setParentKeyOrId($this->issueKey);
2525

2626
$issueService = new IssueService();
2727

tests/WorkLogTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public function testGetWorkLog()
1515
$issueService = new IssueService();
1616

1717
// get issue's worklog
18-
$worklogs = $issueService->getWorklog($this->issueKey)->getWorklogs();
18+
$pwl = $issueService->getWorklog($this->issueKey);
19+
$worklogs = $pwl->getWorklogs();
1920

2021
Dumper::dump($worklogs);
2122
} catch (JiraException $e) {

0 commit comments

Comments
 (0)