Skip to content

Added ProjectType #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ screen_capture.png
bug-description.pdf

.env

# Ignore Vagrant Stuff
.vagrant
Vagrantfile
# Ignore scotch.io box and the folders of them
public/
63 changes: 57 additions & 6 deletions src/Project/ProjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace JiraRestApi\Project;

use JiraRestApi\Issue\Reporter;
use JiraRestApi\Issue\IssueType;
use JiraRestApi\Issue\Reporter;

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

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

return $prjs;
Expand All @@ -36,12 +36,12 @@ public function getAllProjects()
*/
public function get($projectIdOrKey)
{
$ret = $this->exec($this->uri."/$projectIdOrKey", null);
$ret = $this->exec($this->uri . "/$projectIdOrKey", null);

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

$prj = $this->json_mapper->map(
json_decode($ret), new Project()
json_decode($ret), new Project()
);

return $prj;
Expand Down Expand Up @@ -69,12 +69,63 @@ public function getAssignable($projectIdOrKey)

public function getStatuses($projectIdOrKey)
{
$ret = $this->exec($this->uri."/$projectIdOrKey/statuses", null);
$ret = $this->exec($this->uri . "/$projectIdOrKey/statuses", null);
$json = json_decode($ret);
$results = array_map(function ($elem) {
return $this->json_mapper->map($elem, new IssueType());
}, $json);

return $results;
}

/**
* @return ProjectType[]
*/
public function getProjectTypes()
{
$ret = $this->exec($this->uri . "/type");

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

$json = json_decode($ret);
$results = array_map(function ($elem) {
return $this->json_mapper->map($elem, new ProjectType());
}, $json);

return $results;
}

/**
* @param string|int $key
* @return ProjectType
*/
public function getProjectType($key)
{
$ret = $this->exec($this->uri . "/type/$key");

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

$type = $this->json_mapper->map(
json_decode($ret, false), new ProjectType()
);

return $type;
}

/**
* @param string|int $key
* @return ProjectType
*/
public function getAccessibleProjectType($key)
{
$ret = $this->exec($this->uri . "/type/$key/accessible");

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

$type = $this->json_mapper->map(
json_decode($ret, false), new ProjectType()
);

return $type;
}
}
25 changes: 25 additions & 0 deletions src/Project/ProjectType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace JiraRestApi\Project;

use JiraRestApi\ClassSerialize;

class ProjectType
{
use ClassSerialize;

/** @var string */
public $key;

/** @var string */
public $formattedKey;

/** @var string */
public $descriptionI18nKey;

/** @var string */
public $icon;

/** @var string */
public $color;

}
111 changes: 83 additions & 28 deletions tests/ProjectTest.php
Original file line number Diff line number Diff line change
@@ -1,43 +1,98 @@
<?php

use JiraRestApi\Dumper;
use JiraRestApi\Project\ProjectService;

class ProjectTest extends PHPUnit_Framework_TestCase
{
public function testGetProject()
{
//$this->markTestIncomplete();
try {
$proj = new ProjectService();

$p = $proj->get('TEST');

Dumper::dump($p);
foreach ($p->components as $c) {
echo 'COM : '.$c->name."\n";
}
} catch (HTTPException $e) {
$this->assertTrue(false, $e->getMessage());
}
$proj = new ProjectService();

$p = $proj->get('TEST');

$this->assertTrue($p instanceof JiraRestApi\Project\Project);
$this->assertTrue(strlen($p->key) > 0);
$this->assertTrue(!empty($p->id));
$this->assertTrue(strlen($p->name) > 0);
// $this->assertTrue(strlen($p->projectCategory['name']) > 0);
}

public function testGetProjectLists()
{
//$this->markTestIncomplete();
try {
$proj = new ProjectService();

$prjs = $proj->getAllProjects();

foreach ($prjs as $p) {
echo sprintf("Project Key:%s, Id:%s, Name:%s, projectCategory: %s\n",
$p->key, $p->id, $p->name, $p->projectCategory['name']
);
}
} catch (HTTPException $e) {
$this->assertTrue(false, $e->getMessage());
$proj = new ProjectService();

$prjs = $proj->getAllProjects();

foreach ($prjs as $p) {
$this->assertTrue($p instanceof JiraRestApi\Project\Project);
$this->assertTrue(strlen($p->key) > 0);
$this->assertTrue(!empty($p->id));
$this->assertTrue(strlen($p->name) > 0);
// $this->assertTrue(strlen($p->projectCategory['name']) > 0);
}
}
//

public function testGetProjectTypes()
{
$proj = new ProjectService();

$prjtyps = $proj->getProjectTypes();

foreach ($prjtyps as $pt) {
$this->assertTrue($pt instanceof JiraRestApi\Project\ProjectType);
$this->assertTrue(strlen($pt->key) > 0);
$this->assertTrue(strlen($pt->formattedKey) > 0);
$this->assertTrue(strlen($pt->descriptionI18nKey) > 0);
$this->assertTrue(strlen($pt->color) > 0);
$this->assertTrue(strlen($pt->icon) > 0);
}
}

public function testGetProjectType()
{
$proj = new ProjectService();

$prjtyp = $proj->getProjectType('software');

$this->assertTrue($prjtyp instanceof JiraRestApi\Project\ProjectType);
$this->assertTrue(strlen($prjtyp->key) > 0);
$this->assertTrue(strlen($prjtyp->formattedKey) > 0);
$this->assertTrue(strlen($prjtyp->descriptionI18nKey) > 0);
$this->assertTrue(strlen($prjtyp->color) > 0);
$this->assertTrue(strlen($prjtyp->icon) > 0);
}

/**
* @expectedException JiraRestApi\JiraException
*/
public function testGetProjectTypeException()
{
$proj = new ProjectService();

$prjtyp = $proj->getProjectType('foobar');
}

public function testGetProjectAccessible()
{
$proj = new ProjectService();

$prjtyp = $proj->getAccessibleProjectType('business');

$this->assertTrue($prjtyp instanceof JiraRestApi\Project\ProjectType);
$this->assertTrue(strlen($prjtyp->key) > 0);
$this->assertTrue(strlen($prjtyp->formattedKey) > 0);
$this->assertTrue(strlen($prjtyp->descriptionI18nKey) > 0);
$this->assertTrue(strlen($prjtyp->color) > 0);
$this->assertTrue(strlen($prjtyp->icon) > 0);
}

/**
* @expectedException JiraRestApi\JiraException
*/
public function testGetProjectAccessibleException()
{
$proj = new ProjectService();

$prjtyp = $proj->getAccessibleProjectType('foobar');
}
}