Skip to content

Commit 815d23b

Browse files
committed
Added ProjectType
1 parent 9f22245 commit 815d23b

File tree

4 files changed

+171
-34
lines changed

4 files changed

+171
-34
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,9 @@ screen_capture.png
2626
bug-description.pdf
2727

2828
.env
29+
30+
# Ignore Vagrant Stuff
31+
.vagrant
32+
Vagrantfile
33+
# Ignore scotch.io box and the folders of them
34+
public/

src/Project/ProjectService.php

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace JiraRestApi\Project;
44

5-
use JiraRestApi\Issue\Reporter;
65
use JiraRestApi\Issue\IssueType;
6+
use JiraRestApi\Issue\Reporter;
77

88
class ProjectService extends \JiraRestApi\JiraClient
99
{
@@ -19,7 +19,7 @@ public function getAllProjects()
1919
$ret = $this->exec($this->uri, null);
2020

2121
$prjs = $this->json_mapper->mapArray(
22-
json_decode($ret, false), new \ArrayObject(), '\JiraRestApi\Project\Project'
22+
json_decode($ret, false), new \ArrayObject(), '\JiraRestApi\Project\Project'
2323
);
2424

2525
return $prjs;
@@ -36,12 +36,12 @@ public function getAllProjects()
3636
*/
3737
public function get($projectIdOrKey)
3838
{
39-
$ret = $this->exec($this->uri."/$projectIdOrKey", null);
39+
$ret = $this->exec($this->uri . "/$projectIdOrKey", null);
4040

41-
$this->log->addInfo('Result='.$ret);
41+
$this->log->addInfo('Result=' . $ret);
4242

4343
$prj = $this->json_mapper->map(
44-
json_decode($ret), new Project()
44+
json_decode($ret), new Project()
4545
);
4646

4747
return $prj;
@@ -69,12 +69,63 @@ public function getAssignable($projectIdOrKey)
6969

7070
public function getStatuses($projectIdOrKey)
7171
{
72-
$ret = $this->exec($this->uri."/$projectIdOrKey/statuses", null);
72+
$ret = $this->exec($this->uri . "/$projectIdOrKey/statuses", null);
7373
$json = json_decode($ret);
7474
$results = array_map(function ($elem) {
7575
return $this->json_mapper->map($elem, new IssueType());
7676
}, $json);
7777

7878
return $results;
7979
}
80+
81+
/**
82+
* @return ProjectType[]
83+
*/
84+
public function getProjectTypes()
85+
{
86+
$ret = $this->exec($this->uri . "/type");
87+
88+
$this->log->addInfo('Result=' . $ret);
89+
90+
$json = json_decode($ret);
91+
$results = array_map(function ($elem) {
92+
return $this->json_mapper->map($elem, new ProjectType());
93+
}, $json);
94+
95+
return $results;
96+
}
97+
98+
/**
99+
* @param string|int $key
100+
* @return ProjectType
101+
*/
102+
public function getProjectType($key)
103+
{
104+
$ret = $this->exec($this->uri . "/type/$key");
105+
106+
$this->log->addInfo('Result=' . $ret);
107+
108+
$type = $this->json_mapper->map(
109+
json_decode($ret, false), new ProjectType()
110+
);
111+
112+
return $type;
113+
}
114+
115+
/**
116+
* @param string|int $key
117+
* @return ProjectType
118+
*/
119+
public function getAccessibleProjectType($key)
120+
{
121+
$ret = $this->exec($this->uri . "/type/$key/accessible");
122+
123+
$this->log->addInfo('Result=' . $ret);
124+
125+
$type = $this->json_mapper->map(
126+
json_decode($ret, false), new ProjectType()
127+
);
128+
129+
return $type;
130+
}
80131
}

src/Project/ProjectType.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
namespace JiraRestApi\Project;
3+
4+
use JiraRestApi\ClassSerialize;
5+
6+
class ProjectType
7+
{
8+
use ClassSerialize;
9+
10+
/** @var string */
11+
public $key;
12+
13+
/** @var string */
14+
public $formattedKey;
15+
16+
/** @var string */
17+
public $descriptionI18nKey;
18+
19+
/** @var string */
20+
public $icon;
21+
22+
/** @var string */
23+
public $color;
24+
25+
}

tests/ProjectTest.php

Lines changed: 83 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,98 @@
11
<?php
22

3-
use JiraRestApi\Dumper;
43
use JiraRestApi\Project\ProjectService;
54

65
class ProjectTest extends PHPUnit_Framework_TestCase
76
{
87
public function testGetProject()
98
{
10-
//$this->markTestIncomplete();
11-
try {
12-
$proj = new ProjectService();
13-
14-
$p = $proj->get('TEST');
15-
16-
Dumper::dump($p);
17-
foreach ($p->components as $c) {
18-
echo 'COM : '.$c->name."\n";
19-
}
20-
} catch (HTTPException $e) {
21-
$this->assertTrue(false, $e->getMessage());
22-
}
9+
$proj = new ProjectService();
10+
11+
$p = $proj->get('TEST');
12+
13+
$this->assertTrue($p instanceof JiraRestApi\Project\Project);
14+
$this->assertTrue(strlen($p->key) > 0);
15+
$this->assertTrue(!empty($p->id));
16+
$this->assertTrue(strlen($p->name) > 0);
17+
// $this->assertTrue(strlen($p->projectCategory['name']) > 0);
2318
}
2419

2520
public function testGetProjectLists()
2621
{
27-
//$this->markTestIncomplete();
28-
try {
29-
$proj = new ProjectService();
30-
31-
$prjs = $proj->getAllProjects();
32-
33-
foreach ($prjs as $p) {
34-
echo sprintf("Project Key:%s, Id:%s, Name:%s, projectCategory: %s\n",
35-
$p->key, $p->id, $p->name, $p->projectCategory['name']
36-
);
37-
}
38-
} catch (HTTPException $e) {
39-
$this->assertTrue(false, $e->getMessage());
22+
$proj = new ProjectService();
23+
24+
$prjs = $proj->getAllProjects();
25+
26+
foreach ($prjs as $p) {
27+
$this->assertTrue($p instanceof JiraRestApi\Project\Project);
28+
$this->assertTrue(strlen($p->key) > 0);
29+
$this->assertTrue(!empty($p->id));
30+
$this->assertTrue(strlen($p->name) > 0);
31+
// $this->assertTrue(strlen($p->projectCategory['name']) > 0);
4032
}
4133
}
42-
//
34+
35+
public function testGetProjectTypes()
36+
{
37+
$proj = new ProjectService();
38+
39+
$prjtyps = $proj->getProjectTypes();
40+
41+
foreach ($prjtyps as $pt) {
42+
$this->assertTrue($pt instanceof JiraRestApi\Project\ProjectType);
43+
$this->assertTrue(strlen($pt->key) > 0);
44+
$this->assertTrue(strlen($pt->formattedKey) > 0);
45+
$this->assertTrue(strlen($pt->descriptionI18nKey) > 0);
46+
$this->assertTrue(strlen($pt->color) > 0);
47+
$this->assertTrue(strlen($pt->icon) > 0);
48+
}
49+
}
50+
51+
public function testGetProjectType()
52+
{
53+
$proj = new ProjectService();
54+
55+
$prjtyp = $proj->getProjectType('software');
56+
57+
$this->assertTrue($prjtyp instanceof JiraRestApi\Project\ProjectType);
58+
$this->assertTrue(strlen($prjtyp->key) > 0);
59+
$this->assertTrue(strlen($prjtyp->formattedKey) > 0);
60+
$this->assertTrue(strlen($prjtyp->descriptionI18nKey) > 0);
61+
$this->assertTrue(strlen($prjtyp->color) > 0);
62+
$this->assertTrue(strlen($prjtyp->icon) > 0);
63+
}
64+
65+
/**
66+
* @expectedException JiraRestApi\JiraException
67+
*/
68+
public function testGetProjectTypeException()
69+
{
70+
$proj = new ProjectService();
71+
72+
$prjtyp = $proj->getProjectType('foobar');
73+
}
74+
75+
public function testGetProjectAccessible()
76+
{
77+
$proj = new ProjectService();
78+
79+
$prjtyp = $proj->getAccessibleProjectType('business');
80+
81+
$this->assertTrue($prjtyp instanceof JiraRestApi\Project\ProjectType);
82+
$this->assertTrue(strlen($prjtyp->key) > 0);
83+
$this->assertTrue(strlen($prjtyp->formattedKey) > 0);
84+
$this->assertTrue(strlen($prjtyp->descriptionI18nKey) > 0);
85+
$this->assertTrue(strlen($prjtyp->color) > 0);
86+
$this->assertTrue(strlen($prjtyp->icon) > 0);
87+
}
88+
89+
/**
90+
* @expectedException JiraRestApi\JiraException
91+
*/
92+
public function testGetProjectAccessibleException()
93+
{
94+
$proj = new ProjectService();
95+
96+
$prjtyp = $proj->getAccessibleProjectType('foobar');
97+
}
4398
}

0 commit comments

Comments
 (0)