From 24a1fc24c3c55e801c2ce22c92bb4aae319fa9be Mon Sep 17 00:00:00 2001 From: KwangSeob Jeong Date: Fri, 5 Jun 2015 20:48:05 +0900 Subject: [PATCH] php-cs-fixer --- src/Issue/Attachment.php | 17 +- src/Issue/Comment.php | 113 +++--- src/Issue/Comments.php | 15 +- src/Issue/Issue.php | 18 +- src/Issue/IssueField.php | 273 +++++++------ src/Issue/IssueService.php | 128 ++++--- src/Issue/IssueType.php | 15 +- src/Issue/Priority.php | 13 +- src/Issue/Reporter.php | 15 +- src/Issue/Transition.php | 90 ++--- src/Issue/Version.php | 13 +- src/JiraClient.php | 673 +++++++++++++++++---------------- src/Project/Component.php | 21 +- src/Project/Project.php | 48 ++- src/Project/ProjectService.php | 43 ++- tests/CurlTest.php | 33 +- tests/IssueTest.php | 248 ++++++------ tests/ProjectTest.php | 61 ++- tests/bootstrap.php | 4 +- 19 files changed, 942 insertions(+), 899 deletions(-) diff --git a/src/Issue/Attachment.php b/src/Issue/Attachment.php index 179df05d..ae3750e5 100644 --- a/src/Issue/Attachment.php +++ b/src/Issue/Attachment.php @@ -2,8 +2,9 @@ namespace JiraRestApi\Issue; -class Attachment implements \JsonSerializable{ - /* @var string */ +class Attachment implements \JsonSerializable +{ + /* @var string */ public $self; /* @var string */ @@ -29,11 +30,9 @@ class Attachment implements \JsonSerializable{ /* @var string */ public $thumbnail; - - public function jsonSerialize() - { - return array_filter(get_object_vars($this)); - } -} -?> \ No newline at end of file + public function jsonSerialize() + { + return array_filter(get_object_vars($this)); + } +} diff --git a/src/Issue/Comment.php b/src/Issue/Comment.php index 11cf6cd5..2957f27e 100644 --- a/src/Issue/Comment.php +++ b/src/Issue/Comment.php @@ -2,70 +2,79 @@ namespace JiraRestApi\Issue; -class Visibility { - private $type; - private $value; - - public function setType($type) { - $this->type = $type; - } - public function setValue($value) { - $this->value = $value; - } - - public function getType() { - return $this->type; - } - public function getValue() { - return $this->value; - } +class Visibility +{ + private $type; + private $value; + + public function setType($type) + { + $this->type = $type; + } + public function setValue($value) + { + $this->value = $value; + } + + public function getType() + { + return $this->type; + } + public function getValue() + { + return $this->value; + } } -class Comment implements \JsonSerializable { - /* @var string */ - public $self; +class Comment implements \JsonSerializable +{ + /* @var string */ + public $self; - /* @var string */ - public $id; + /* @var string */ + public $id; - /* @var Reporter */ - public $author; + /* @var Reporter */ + public $author; - /* @var string */ - public $body; + /* @var string */ + public $body; - /* @var Reporter */ - public $updateAuthor; + /* @var Reporter */ + public $updateAuthor; - /* @var DateTime */ - public $created; + /* @var DateTime */ + public $created; - /* @var DateTime */ - public $updated; + /* @var DateTime */ + public $updated; - /** - * @var Visibility - */ - public $visibility; + /** + * @var Visibility + */ + public $visibility; - public function setBody($body) { - $this->body = $body; - return $this; + public function setBody($body) + { + $this->body = $body; + + return $this; } - public function setVisibility($type, $vvalue) { - if (is_null($this->visibility)) - $this->visibility = new Visibility; + public function setVisibility($type, $vvalue) + { + if (is_null($this->visibility)) { + $this->visibility = new Visibility(); + } + + $this->visibility->setType($type); + $this->visibility->setValue($vvalue); - $this->visibility->setType($type); - $this->visibility->setValue($vvalue); - return $this; + return $this; } - - public function jsonSerialize() - { - return array_filter(get_object_vars($this)); - } -} -?> \ No newline at end of file + public function jsonSerialize() + { + return array_filter(get_object_vars($this)); + } +} diff --git a/src/Issue/Comments.php b/src/Issue/Comments.php index 2b3106ab..44e2e369 100644 --- a/src/Issue/Comments.php +++ b/src/Issue/Comments.php @@ -2,8 +2,9 @@ namespace JiraRestApi\Issue; -class Comments implements \JsonSerializable { - /* @var int */ +class Comments implements \JsonSerializable +{ + /* @var int */ public $startAt; /* @var int */ @@ -15,10 +16,8 @@ class Comments implements \JsonSerializable { /* @var CommentList[\JiraRestApi\Issue\Comment] */ public $comments; - public function jsonSerialize() - { - return array_filter(get_object_vars($this)); - } + public function jsonSerialize() + { + return array_filter(get_object_vars($this)); + } } - -?> \ No newline at end of file diff --git a/src/Issue/Issue.php b/src/Issue/Issue.php index 0fafdecb..f0a12ea2 100644 --- a/src/Issue/Issue.php +++ b/src/Issue/Issue.php @@ -2,14 +2,16 @@ namespace JiraRestApi\Issue; -class Issue implements \JsonSerializable{ +class Issue implements \JsonSerializable +{ /** - * return only if Project query by key(not id) + * return only if Project query by key(not id). + * * @var string */ public $expand; - /* @var string */ + /* @var string */ public $self; /* @var string */ @@ -21,10 +23,8 @@ class Issue implements \JsonSerializable{ /* @var IssueField */ public $fields; - public function jsonSerialize() - { - return array_filter(get_object_vars($this)); - } + public function jsonSerialize() + { + return array_filter(get_object_vars($this)); + } } - -?> \ No newline at end of file diff --git a/src/Issue/IssueField.php b/src/Issue/IssueField.php index 7c1d03ea..955c39d9 100644 --- a/src/Issue/IssueField.php +++ b/src/Issue/IssueField.php @@ -2,17 +2,19 @@ namespace JiraRestApi\Issue; -class IssueField implements \JsonSerializable { - public function __construct($updateIssue = false) { - if ($updateIssue != true) { - $this->project = new \JiraRestApi\Project\Project(); - - $this->assignee = new \JiraRestApi\Issue\Reporter(); - $this->priority = new \JiraRestApi\Issue\Priority(); - $this->versions = array(); - - $this->issuetype = new \JiraRestApi\Issue\IssueType(); - } +class IssueField implements \JsonSerializable +{ + public function __construct($updateIssue = false) + { + if ($updateIssue != true) { + $this->project = new \JiraRestApi\Project\Project(); + + $this->assignee = new \JiraRestApi\Issue\Reporter(); + $this->priority = new \JiraRestApi\Issue\Priority(); + $this->versions = array(); + + $this->issuetype = new \JiraRestApi\Issue\IssueType(); + } } public function jsonSerialize() @@ -20,165 +22,194 @@ public function jsonSerialize() return array_filter(get_object_vars($this)); } - public function getProjectKey() { - return $this->project->key; + public function getProjectKey() + { + return $this->project->key; } - public function getProjectId() { - return $this->project->id; + public function getProjectId() + { + return $this->project->id; } - public function setProjectKey($key) { - $this->project->key = $key; - return $this; + public function setProjectKey($key) + { + $this->project->key = $key; + + return $this; } - public function setProjectId($id) { - $this->project->id = $id; - return $this; + public function setProjectId($id) + { + $this->project->id = $id; + + return $this; } - public function setIssueType($name) { - if (is_null($this->issuetype)) - $this->issuetype = new \JiraRestApi\Issue\IssueType(); + public function setIssueType($name) + { + if (is_null($this->issuetype)) { + $this->issuetype = new \JiraRestApi\Issue\IssueType(); + } + + $this->issuetype->name = $name; - $this->issuetype->name = $name; - return $this; + return $this; } - public function setSummary($summary) { - $this->summary = $summary; - return $this; + public function setSummary($summary) + { + $this->summary = $summary; + + return $this; } - public function setReporterName($name) { - if (is_null($this->reporter)) - $this->reporter = new \JiraRestApi\Issue\Reporter(); + public function setReporterName($name) + { + if (is_null($this->reporter)) { + $this->reporter = new \JiraRestApi\Issue\Reporter(); + } + + $this->reporter->name = $name; - $this->reporter->name = $name; - return $this; + return $this; } - public function setAssigneeName($name) { - if (is_null($this->assignee)) - $this->assignee = new \JiraRestApi\Issue\Reporter(); + public function setAssigneeName($name) + { + if (is_null($this->assignee)) { + $this->assignee = new \JiraRestApi\Issue\Reporter(); + } + + $this->assignee->name = $name; - $this->assignee->name = $name; - return $this; + return $this; } - public function setPriorityName($name) { - if (is_null($this->priority)) - $this->priority = new \JiraRestApi\Issue\Priority(); + public function setPriorityName($name) + { + if (is_null($this->priority)) { + $this->priority = new \JiraRestApi\Issue\Priority(); + } + + $this->priority->name = $name; - $this->priority->name = $name; - return $this; + return $this; } - public function setDescription($description) { - $this->description = $description; - return $this; + public function setDescription($description) + { + $this->description = $description; + + return $this; } - public function addVersion($name) { - if (is_null($this->versions)) - $this->versions = array(); - - $v = new Version(); - $v->name = $name; - array_push($this->versions, $v); - return $this; + public function addVersion($name) + { + if (is_null($this->versions)) { + $this->versions = array(); + } + + $v = new Version(); + $v->name = $name; + array_push($this->versions, $v); + + return $this; } - public function addComment($comment) { - if (is_null($this->comments)) - $this->comments = new \JiraRestApi\Issue\Comments(); + public function addComment($comment) + { + if (is_null($this->comments)) { + $this->comments = new \JiraRestApi\Issue\Comments(); + } + + array_push($this->versions, $v); - array_push($this->versions, $v); - return $this; + return $this; } - public function addLabel($label) { - if (is_null($this->labels)) - $this->labels = array(); + public function addLabel($label) + { + if (is_null($this->labels)) { + $this->labels = array(); + } + + array_push($this->labels, $label); - array_push($this->labels, $label); - return $this; + return $this; } - /** @var string */ - public $summary; + /** @var string */ + public $summary; - /** @var string */ - //public $progress; + /** @var string */ + //public $progress; - /** @var string */ - public $timetracking; + /** @var string */ + public $timetracking; - /** @var IssueType */ - public $issuetype; + /** @var IssueType */ + public $issuetype; - /** @var string */ - public $timespent; - - /** @var Reporter */ - public $reporter; + /** @var string */ + public $timespent; - /** @var DateTime */ - public $created; + /** @var Reporter */ + public $reporter; - /** @var DateTime */ - public $updated; + /** @var DateTime */ + public $created; - /** @var string */ - public $description; + /** @var DateTime */ + public $updated; - /** @var Priority */ - public $priority; - - /** @var IssueStatus */ - public $status; + /** @var string */ + public $description; - /** @var string */ - public $labels; + /** @var Priority */ + public $priority; - /** @var JiraRestApi\Project\Project */ - public $project; + /** @var IssueStatus */ + public $status; - /** @var string */ - public $environment; - - /** @var string */ - public $components; + /** @var string */ + public $labels; - /** @var Comments */ - public $comments; - - /** @var string */ - public $votes; + /** @var JiraRestApi\Project\Project */ + public $project; - /** @var string */ - public $resolution; + /** @var string */ + public $environment; - /** @var string */ - public $fixVersions; + /** @var string */ + public $components; - /** @var Reporter */ - public $creator; + /** @var Comments */ + public $comments; - /** @var string */ - public $watches; + /** @var string */ + public $votes; - /** @var string */ - public $worklog; + /** @var string */ + public $resolution; - /** @var Reporter */ - public $assignee; + /** @var string */ + public $fixVersions; - /* @var VersionList[\JiraRestApi\Issue\Version] */ - public $versions; + /** @var Reporter */ + public $creator; - /** @var AttachmentList[\JiraRestApi\Issue\Attachment] */ - public $attachments; -} + /** @var string */ + public $watches; -?> \ No newline at end of file + /** @var string */ + public $worklog; + + /** @var Reporter */ + public $assignee; + + /* @var VersionList[\JiraRestApi\Issue\Version] */ + public $versions; + + /** @var AttachmentList[\JiraRestApi\Issue\Attachment] */ + public $attachments; +} diff --git a/src/Issue/IssueService.php b/src/Issue/IssueService.php index 9ed48340..b77c6644 100644 --- a/src/Issue/IssueService.php +++ b/src/Issue/IssueService.php @@ -2,22 +2,25 @@ namespace JiraRestApi\Issue; -class IssueService extends \JiraRestApi\JiraClient { - private $uri = "/issue"; +class IssueService extends \JiraRestApi\JiraClient +{ + private $uri = '/issue'; - public function __construct() { - parent::__construct(); + public function __construct() + { + parent::__construct(); } /** - * get all project list - * + * get all project list. + * * @return Issue class */ - public function get($issueIdOrKey) { - $ret = $this->exec($this->uri . "/$issueIdOrKey", null); + public function get($issueIdOrKey) + { + $ret = $this->exec($this->uri."/$issueIdOrKey", null); - $this->log->addInfo("Result=\n" . $ret ); + $this->log->addInfo("Result=\n".$ret); $issue = $this->json_mapper->map( json_decode($ret), new Issue() @@ -27,13 +30,14 @@ public function get($issueIdOrKey) { } /** - * create new issue - * + * create new issue. + * * @param $issue object of Issue class - * + * * @return created issue key */ - public function create($issueField) { + public function create($issueField) + { $issue = new Issue(); // serilize only not null field. @@ -41,9 +45,9 @@ public function create($issueField) { $data = json_encode($issue); - $this->log->addInfo("Create Issue=\n" . $data ); + $this->log->addInfo("Create Issue=\n".$data); - $ret = $this->exec($this->uri, $data, "POST"); + $ret = $this->exec($this->uri, $data, 'POST'); $issue = $this->json_mapper->map( json_decode($ret), new Issue() @@ -53,21 +57,21 @@ public function create($issueField) { } /** - * Add one or more file to an issue - * + * Add one or more file to an issue. + * * @param issueIdOrKey Issue id or key * @param filePathArray attachment file path. - * + * * @return */ - public function addAttachments($issueIdOrKey, $filePathArray) { - - $results = $this->upload($this->uri . "/$issueIdOrKey/attachments", $filePathArray); + public function addAttachments($issueIdOrKey, $filePathArray) + { + $results = $this->upload($this->uri."/$issueIdOrKey/attachments", $filePathArray); - $this->log->addInfo("addAttachments result=" . var_export($results, true)); + $this->log->addInfo('addAttachments result='.var_export($results, true)); $resArr = array(); - foreach($results as $ret) { + foreach ($results as $ret) { array_push($resArr, $this->json_mapper->mapArray( json_decode($ret), new \ArrayObject(), '\JiraRestApi\Issue\Attachment' ) @@ -78,14 +82,15 @@ public function addAttachments($issueIdOrKey, $filePathArray) { } /** - * update issue - * + * update issue. + * * @param $issueIdOrKey Issue Key - * @param $issueField object of Issue class - * + * @param $issueField object of Issue class + * * @return created issue key */ - public function update($issueIdOrKey, $issueField) { + public function update($issueIdOrKey, $issueField) + { $issue = new Issue(); // serilize only not null field. @@ -95,30 +100,30 @@ public function update($issueIdOrKey, $issueField) { $data = json_encode($issue); - $this->log->addInfo("Update Issue=\n" . $data ); + $this->log->addInfo("Update Issue=\n".$data); - $ret = $this->exec($this->uri . "/$issueIdOrKey", $data, "PUT"); + $ret = $this->exec($this->uri."/$issueIdOrKey", $data, 'PUT'); return $ret; } /** * Adds a new comment to an issue. - * + * * @param issueIdOrKey Issue id or key * @param comment . - * + * * @return Comment class */ - public function addComment($issueIdOrKey, $comment) { - + public function addComment($issueIdOrKey, $comment) + { $this->log->addInfo("addComment=\n"); $data = json_encode($comment); - - $ret = $this->exec($this->uri . "/$issueIdOrKey/comment", $data); - $this->log->addDebug("add comment result=" . var_export($ret, true)); + $ret = $this->exec($this->uri."/$issueIdOrKey/comment", $data); + + $this->log->addDebug('add comment result='.var_export($ret, true)); $comment = $this->json_mapper->map( json_decode($ret), new Comment() ); @@ -128,16 +133,16 @@ public function addComment($issueIdOrKey, $comment) { /** * Get a list of the transitions possible for this issue by the current user, along with fields that are required and their types. - * + * * @param issueIdOrKey Issue id or key - * + * * @return array of Transition class */ - public function getTransition($issueIdOrKey) { - - $ret = $this->exec($this->uri . "/$issueIdOrKey/transitions"); + public function getTransition($issueIdOrKey) + { + $ret = $this->exec($this->uri."/$issueIdOrKey/transitions"); - $this->log->addDebug("getTransitions result=" . var_export($ret, true)); + $this->log->addDebug('getTransitions result='.var_export($ret, true)); $data = json_encode(json_decode($ret)->transitions); @@ -149,36 +154,37 @@ public function getTransition($issueIdOrKey) { } /** - * find transition id by transition's to field name(aka 'Resolved') - * - */ - public function findTransitonId($issueIdOrKey, $transitionToName) { - $this->log->addDebug("findTransitonId="); + * find transition id by transition's to field name(aka 'Resolved'). + */ + public function findTransitonId($issueIdOrKey, $transitionToName) + { + $this->log->addDebug('findTransitonId='); $ret = $this->getTransition($issueIdOrKey); - - foreach($ret as $trans) { + + foreach ($ret as $trans) { $toName = $trans->to->name; - - $this->log->addDebug("getTransitions result=" . var_export($ret, true)); - if (strcmp($toName, $transitionToName) == 0){ + $this->log->addDebug('getTransitions result='.var_export($ret, true)); + + if (strcmp($toName, $transitionToName) == 0) { return $trans->id; } } - return null; - } + return; + } /** * Perform a transition on an issue. - * + * * @param issueIdOrKey Issue id or key - * + * * @return nothing - if transition was successful return http 204(no contents) */ - public function transition($issueIdOrKey, $transition) { - $this->log->addDebug("transition=" . var_export($transition, true)); + public function transition($issueIdOrKey, $transition) + { + $this->log->addDebug('transition='.var_export($transition, true)); if (!isset($transition->transition['id'])) { $transition->transition['id'] = $this->findTransitonId($issueIdOrKey, $transition->transition['name']); @@ -188,9 +194,9 @@ public function transition($issueIdOrKey, $transition) { $this->log->addDebug("transition req=$data\n"); - $ret = $this->exec($this->uri . "/$issueIdOrKey/transitions", $data, "POST"); + $ret = $this->exec($this->uri."/$issueIdOrKey/transitions", $data, 'POST'); - $this->log->addDebug("getTransitions result=" . var_export($ret, true)); + $this->log->addDebug('getTransitions result='.var_export($ret, true)); } } diff --git a/src/Issue/IssueType.php b/src/Issue/IssueType.php index f4a2871c..7bd250d1 100644 --- a/src/Issue/IssueType.php +++ b/src/Issue/IssueType.php @@ -2,7 +2,8 @@ namespace JiraRestApi\Issue; -class IssueType implements \JsonSerializable{ +class IssueType implements \JsonSerializable +{ /* @var string */ public $self; @@ -16,15 +17,13 @@ class IssueType implements \JsonSerializable{ public $iconUrl; /* @var string */ - public $name; + public $name; /* @var bool */ public $subtask; - public function jsonSerialize() - { - return array_filter(get_object_vars($this)); - } + public function jsonSerialize() + { + return array_filter(get_object_vars($this)); + } } - -?> \ No newline at end of file diff --git a/src/Issue/Priority.php b/src/Issue/Priority.php index 76a6dbb8..472c69bc 100644 --- a/src/Issue/Priority.php +++ b/src/Issue/Priority.php @@ -2,8 +2,9 @@ namespace JiraRestApi\Issue; -class Priority implements \JsonSerializable{ - /* @var string */ +class Priority implements \JsonSerializable +{ + /* @var string */ public $self; /* @var string */ @@ -16,9 +17,7 @@ class Priority implements \JsonSerializable{ public $id; public function jsonSerialize() - { - return array_filter(get_object_vars($this)); - } + { + return array_filter(get_object_vars($this)); + } } - -?> \ No newline at end of file diff --git a/src/Issue/Reporter.php b/src/Issue/Reporter.php index f66b138a..1af0ca1d 100644 --- a/src/Issue/Reporter.php +++ b/src/Issue/Reporter.php @@ -2,8 +2,9 @@ namespace JiraRestApi\Issue; -class Reporter implements \JsonSerializable{ - /* @var string */ +class Reporter implements \JsonSerializable +{ + /* @var string */ public $self; /* @var string */ @@ -21,10 +22,8 @@ class Reporter implements \JsonSerializable{ /* @var string */ public $active; - public function jsonSerialize() - { - return array_filter(get_object_vars($this)); - } + public function jsonSerialize() + { + return array_filter(get_object_vars($this)); + } } - -?> \ No newline at end of file diff --git a/src/Issue/Transition.php b/src/Issue/Transition.php index 34b0d4d4..e1b0e3a9 100644 --- a/src/Issue/Transition.php +++ b/src/Issue/Transition.php @@ -2,10 +2,11 @@ namespace JiraRestApi\Issue; -use \JiraRestApi\Issue\IssueField; +use JiraRestApi\Issue\IssueField; -class TransitionTo { - /* @var string */ +class TransitionTo +{ + /* @var string */ public $self; /* @var string */ @@ -15,23 +16,23 @@ class TransitionTo { public $iconUrl; /** Closed, Resolved, etc.. - * @var string + * @var string */ public $name; /* @var string */ public $id; - /* @var array */ + /* @var array */ public $statusCategory; } /** - * Issue Transition mapping class - * - */ -class Transition implements \JsonSerializable{ - /* @var string */ + * Issue Transition mapping class. + */ +class Transition implements \JsonSerializable +{ + /* @var string */ public $id; /* @var string */ @@ -49,37 +50,40 @@ class Transition implements \JsonSerializable{ /* @var array */ public $transition; - public $update; - - public function setTransitionName($name) { - if (is_null($this->transition)) - $this->transition = array(); - - $this->transition['name'] = $name; - } - - public function setTransitionId($id) { - if (is_null($this->transition)) - $this->transition = array(); - - $this->transition['id'] = $id; - } - - public function setCommentBody($commentBody) { - if (is_null($this->update)) { - $this->update = array(); - $this->update['comment'] = array(); - } - - $ar = array(); - $ar['add']['body'] = $commentBody; - array_push($this->update['comment'], $ar); - } - - public function jsonSerialize() - { - return array_filter(get_object_vars($this)); - } + public $update; + + public function setTransitionName($name) + { + if (is_null($this->transition)) { + $this->transition = array(); + } + + $this->transition['name'] = $name; + } + + public function setTransitionId($id) + { + if (is_null($this->transition)) { + $this->transition = array(); + } + + $this->transition['id'] = $id; + } + + public function setCommentBody($commentBody) + { + if (is_null($this->update)) { + $this->update = array(); + $this->update['comment'] = array(); + } + + $ar = array(); + $ar['add']['body'] = $commentBody; + array_push($this->update['comment'], $ar); + } + + public function jsonSerialize() + { + return array_filter(get_object_vars($this)); + } } - -?> \ No newline at end of file diff --git a/src/Issue/Version.php b/src/Issue/Version.php index b8620dc1..0e54c423 100644 --- a/src/Issue/Version.php +++ b/src/Issue/Version.php @@ -2,8 +2,9 @@ namespace JiraRestApi\Issue; -class Version implements \JsonSerializable{ - /* @var string */ +class Version implements \JsonSerializable +{ + /* @var string */ public $self; /* @var string */ @@ -25,9 +26,7 @@ class Version implements \JsonSerializable{ public $releaseDate; public function jsonSerialize() - { - return array_filter(get_object_vars($this)); - } + { + return array_filter(get_object_vars($this)); + } } - -?> \ No newline at end of file diff --git a/src/JiraClient.php b/src/JiraClient.php index 92567617..e4264f09 100644 --- a/src/JiraClient.php +++ b/src/JiraClient.php @@ -2,97 +2,93 @@ namespace JiraRestApi; -require 'vendor/autoload.php'; - -class JIRAException extends \Exception { } - -use \Monolog\Logger as Logger; -use \Monolog\Handler\StreamHandler; +class JIRAException extends \Exception +{ +} -use \Noodlehaus\Config as Config; +use Monolog\Logger as Logger; +use Monolog\Handler\StreamHandler; /** - * interact jira server with REST API + * interact jira server with REST API. */ -class JiraClient { - /* @var json mapper */ - protected $json_mapper; - - /** @var HTTP response code */ - protected $http_response; - - /** @var JIRA REST API URI */ - private $api_uri = '/rest/api/2'; - - /** @var CURL instrance */ - protected $curl; - - /** @var jira host */ - protected $host; - /** @var jira username */ - protected $username; - /** @var jira password */ - protected $password; - - /** @var Monolog instance */ - protected $log; - - // disable SSL Certification validation - protected $CURLOPT_SSL_VERIFYHOST = false; - // FALSE to stop CURL from verifying the peer's certificate. - protected $CURLOPT_SSL_VERIFYPEER = false; - - // debug curl - protected $CURLOPT_VERBOSE = false; - - protected $LOG_FILE; - protected $LOG_LEVEL; - - private function convertLogLevel($log_level) { - if ($log_level == 'DEBUG') { - return Logger::DEBUG; - } - else if ($log_level == 'INFO') { - return Logger::DEBUG; - } - else if ($log_level == 'WARNING') { - return Logger::WARNING; - } - else if ($log_level == 'ERROR') { - return Logger::ERROR; - } - else { - return Logger::WARNING; - } - } - - // serilize only not null field. - protected function filterNullVariable($haystack) - { - foreach ($haystack as $key => $value) { - if (is_array($value) ) { - $haystack[$key] = $this->filterNullVariable($haystack[$key]); - } else if (is_object($value)) { - $haystack[$key] = $this->filterNullVariable(get_class_vars(get_class($value))); - } - - if (is_null($haystack[$key]) || empty($haystack[$key])) { - unset($haystack[$key]); - } - } - - return $haystack; - } - - public function __construct() - { - $dotenv = new \Dotenv\Dotenv(__DIR__ . '/..'); - $dotenv->load(); - - $dotenv->required(['JIRA_HOST', 'JIRA_USER', 'JIRA_PASS']); - - $this->json_mapper = new \JsonMapper(); - $this->json_mapper->bExceptionOnUndefinedProperty = true; +class JiraClient +{ + /* @var json mapper */ + protected $json_mapper; + + /** @var HTTP response code */ + protected $http_response; + + /** @var JIRA REST API URI */ + private $api_uri = '/rest/api/2'; + + /** @var CURL instrance */ + protected $curl; + + /** @var jira host */ + protected $host; + /** @var jira username */ + protected $username; + /** @var jira password */ + protected $password; + + /** @var Monolog instance */ + protected $log; + + // disable SSL Certification validation + protected $CURLOPT_SSL_VERIFYHOST = false; + // FALSE to stop CURL from verifying the peer's certificate. + protected $CURLOPT_SSL_VERIFYPEER = false; + + // debug curl + protected $CURLOPT_VERBOSE = false; + + protected $LOG_FILE; + protected $LOG_LEVEL; + + private function convertLogLevel($log_level) + { + if ($log_level == 'DEBUG') { + return Logger::DEBUG; + } elseif ($log_level == 'INFO') { + return Logger::DEBUG; + } elseif ($log_level == 'WARNING') { + return Logger::WARNING; + } elseif ($log_level == 'ERROR') { + return Logger::ERROR; + } else { + return Logger::WARNING; + } + } + + // serilize only not null field. + protected function filterNullVariable($haystack) + { + foreach ($haystack as $key => $value) { + if (is_array($value)) { + $haystack[$key] = $this->filterNullVariable($haystack[$key]); + } elseif (is_object($value)) { + $haystack[$key] = $this->filterNullVariable(get_class_vars(get_class($value))); + } + + if (is_null($haystack[$key]) || empty($haystack[$key])) { + unset($haystack[$key]); + } + } + + return $haystack; + } + + public function __construct() + { + $dotenv = new \Dotenv\Dotenv('.'); + $dotenv->load(); + + $dotenv->required(['JIRA_HOST', 'JIRA_USER', 'JIRA_PASS']); + + $this->json_mapper = new \JsonMapper(); + $this->json_mapper->bExceptionOnUndefinedProperty = true; $this->host = $this->env('JIRA_HOST'); $this->username = $this->env('JIRA_USER'); @@ -100,238 +96,241 @@ public function __construct() $this->CURLOPT_SSL_VERIFYHOST = $this->env('CURLOPT_SSL_VERIFYHOST', false); - $this->CURLOPT_SSL_VERIFYPEER = $this->env('CURLOPT_SSL_VERIFYPEER', false); - $this->CURLOPT_VERBOSE = $this->env('CURLOPT_VERBOSE', false); + $this->CURLOPT_SSL_VERIFYPEER = $this->env('CURLOPT_SSL_VERIFYPEER', false); + $this->CURLOPT_VERBOSE = $this->env('CURLOPT_VERBOSE', false); $this->LOG_FILE = $this->env('JIRA_LOG_FILE', 'jira-rest-client.log'); - $this->LOG_LEVEL = $this->convertLogLevel($this->env('JIRA_LOG_LEVEL', 'WARNING')); + $this->LOG_LEVEL = $this->convertLogLevel($this->env('JIRA_LOG_LEVEL', 'WARNING')); - // create logger - $this->log = new Logger('JiraClient'); - $this->log->pushHandler(new StreamHandler($this->LOG_FILE, - $this->LOG_LEVEL)); + // create logger + $this->log = new Logger('JiraClient'); + $this->log->pushHandler(new StreamHandler($this->LOG_FILE, + $this->LOG_LEVEL)); $this->http_response = 200; } - public function exec($context, $post_data = null, $custom_request = null) { - $url = $this->host . $this->api_uri . '/' . preg_replace('/\//', '', $context, 1); - - $this->log->addDebug("Curl $url JsonData=" . $post_data); - - $ch=curl_init(); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_URL, $url); - - // post_data - if (!is_null($post_data)) { - // PUT REQUEST - if (!is_null($custom_request) && $custom_request == "PUT") { - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); - curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); - } - if (!is_null($custom_request) && $custom_request == "DELETE") { - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); - } - else { - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); - } - } - - curl_setopt($ch, CURLOPT_USERPWD, "$this->username:$this->password"); - - curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, $this->CURLOPT_SSL_VERIFYHOST); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->CURLOPT_SSL_VERIFYPEER); - - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, - array('Accept: */*', 'Content-Type: application/json')); - - curl_setopt($ch, CURLOPT_VERBOSE, $this->CURLOPT_VERBOSE); - - $this->log->addDebug('Curl exec=' . $url); - $response = curl_exec($ch); - - // if request failed. - if (!$response) { - $this->http_response = curl_getinfo($ch, CURLINFO_HTTP_CODE); - $body = curl_error($ch); - curl_close($ch); - - //The server successfully processed the request, but is not returning any content. - if ($this->http_response == 204){ - return ""; - } - - // HostNotFound, No route to Host, etc Network error - $this->log->addError("CURL Error: = " . $body); - throw new JIRAException("CURL Error: = " . $body); - } else { - // if request was ok, parsing http response code. - $this->http_response = curl_getinfo($ch, CURLINFO_HTTP_CODE); - - curl_close($ch); - - // don't check 301, 302 because setting CURLOPT_FOLLOWLOCATION - if ($this->http_response != 200 && $this->http_response != 201) { - throw new JIRAException("CURL HTTP Request Failed: Status Code : " - . $this->http_response . ", URL:" . $url - . "\nError Message : " . $response, $this->http_response); - } - } - - return $response; - } - - private function createUploadHandle($url, $upload_file) { - $ch=curl_init(); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_URL, $url); - - // send file - curl_setopt($ch, CURLOPT_POST, true); - - if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 5) { - $attachments = realpath($upload_file); - $filename = basename($upload_file); - - curl_setopt($ch, CURLOPT_POSTFIELDS, - array('file' => '@' . $attachments . ';filename=' . $filename)); - - $this->log->addDebug('using legacy file upload'); - } else { - // CURLFile require PHP > 5.5 - $attachments = new \CURLFile(realpath($upload_file)); - $attachments->setPostFilename( basename($upload_file)); - - curl_setopt($ch, CURLOPT_POSTFIELDS, - array('file'=>$attachments)); - - $this->log->addDebug('using CURLFile=' . var_export($attachments, true)); - } - - curl_setopt($ch, CURLOPT_USERPWD, "$this->username:$this->password"); - - curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, $this->CURLOPT_SSL_VERIFYHOST); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->CURLOPT_SSL_VERIFYPEER); - - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, - array( - 'Accept: */*', - 'Content-Type: multipart/form-data', - 'X-Atlassian-Token: nocheck' - )); - - curl_setopt($ch, CURLOPT_VERBOSE, $this->CURLOPT_VERBOSE); - - $this->log->addDebug('Curl exec=' . $url); - return $ch; - } - - /** - * file upload - * - * @param context url context - * @param filePathArray upload file path. - * - */ - public function upload($context, $filePathArray) { - $url = $this->host . $this->api_uri . '/' . preg_replace('/\//', '', $context, 1); - - // return value - $result_code = 200; - - $chArr = array(); - $results = array(); - $mh = curl_multi_init(); - - for($idx = 0; $idx < count($filePathArray); $idx++) { - $file = $filePathArray[$idx]; - if (file_exists($file) == false) { - $body = "File $file not found"; - $result_code = -1; - goto end; - } - $chArr[$idx] = $this->createUploadHandle($url, $filePathArray[$idx]); - - curl_multi_add_handle($mh, $chArr[$idx]); - } - - $running = null; - do { - curl_multi_exec($mh, $running); - } - while ($running > 0); - - // Get content and remove handles. - for($idx = 0; $idx < count($chArr); $idx++) { - $ch = $chArr[$idx]; - - $results[$idx] = curl_multi_getcontent($ch); - - // if request failed. - if (!$results[$idx]) { - $this->http_response = curl_getinfo($ch, CURLINFO_HTTP_CODE); - $body = curl_error($ch); - - //The server successfully processed the request, but is not returning any content. - if ($this->http_response == 204){ - continue; - } - - // HostNotFound, No route to Host, etc Network error - $result_code = -1; - $body = "CURL Error: = " . $body; - $this->log->addError($body ); - } else { - // if request was ok, parsing http response code. - $result_code = $this->http_response = curl_getinfo($ch, CURLINFO_HTTP_CODE); - - // don't check 301, 302 because setting CURLOPT_FOLLOWLOCATION - if ($this->http_response != 200 && $this->http_response != 201) { - $body = "CURL HTTP Request Failed: Status Code : " - . $this->http_response . ", URL:" . $url - . "\nError Message : " . $response; - $this->log->addError($body); - } - } - } - - // clean up + public function exec($context, $post_data = null, $custom_request = null) + { + $url = $this->host.$this->api_uri.'/'.preg_replace('/\//', '', $context, 1); + + $this->log->addDebug("Curl $url JsonData=".$post_data); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_URL, $url); + + // post_data + if (!is_null($post_data)) { + // PUT REQUEST + if (!is_null($custom_request) && $custom_request == 'PUT') { + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); + } + if (!is_null($custom_request) && $custom_request == 'DELETE') { + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); + } else { + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); + } + } + + curl_setopt($ch, CURLOPT_USERPWD, "$this->username:$this->password"); + + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->CURLOPT_SSL_VERIFYHOST); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->CURLOPT_SSL_VERIFYPEER); + + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, + array('Accept: */*', 'Content-Type: application/json')); + + curl_setopt($ch, CURLOPT_VERBOSE, $this->CURLOPT_VERBOSE); + + $this->log->addDebug('Curl exec='.$url); + $response = curl_exec($ch); + + // if request failed. + if (!$response) { + $this->http_response = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $body = curl_error($ch); + curl_close($ch); + + //The server successfully processed the request, but is not returning any content. + if ($this->http_response == 204) { + return ''; + } + + // HostNotFound, No route to Host, etc Network error + $this->log->addError('CURL Error: = '.$body); + throw new JIRAException('CURL Error: = '.$body); + } else { + // if request was ok, parsing http response code. + $this->http_response = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + curl_close($ch); + + // don't check 301, 302 because setting CURLOPT_FOLLOWLOCATION + if ($this->http_response != 200 && $this->http_response != 201) { + throw new JIRAException('CURL HTTP Request Failed: Status Code : ' + .$this->http_response.', URL:'.$url + ."\nError Message : ".$response, $this->http_response); + } + } + + return $response; + } + + private function createUploadHandle($url, $upload_file) + { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_URL, $url); + + // send file + curl_setopt($ch, CURLOPT_POST, true); + + if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 5) { + $attachments = realpath($upload_file); + $filename = basename($upload_file); + + curl_setopt($ch, CURLOPT_POSTFIELDS, + array('file' => '@'.$attachments.';filename='.$filename)); + + $this->log->addDebug('using legacy file upload'); + } else { + // CURLFile require PHP > 5.5 + $attachments = new \CURLFile(realpath($upload_file)); + $attachments->setPostFilename(basename($upload_file)); + + curl_setopt($ch, CURLOPT_POSTFIELDS, + array('file' => $attachments)); + + $this->log->addDebug('using CURLFile='.var_export($attachments, true)); + } + + curl_setopt($ch, CURLOPT_USERPWD, "$this->username:$this->password"); + + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->CURLOPT_SSL_VERIFYHOST); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->CURLOPT_SSL_VERIFYPEER); + + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, + array( + 'Accept: */*', + 'Content-Type: multipart/form-data', + 'X-Atlassian-Token: nocheck', + )); + + curl_setopt($ch, CURLOPT_VERBOSE, $this->CURLOPT_VERBOSE); + + $this->log->addDebug('Curl exec='.$url); + + return $ch; + } + + /** + * file upload. + * + * @param context url context + * @param filePathArray upload file path. + */ + public function upload($context, $filePathArray) + { + $url = $this->host.$this->api_uri.'/'.preg_replace('/\//', '', $context, 1); + + // return value + $result_code = 200; + + $chArr = array(); + $results = array(); + $mh = curl_multi_init(); + + for ($idx = 0; $idx < count($filePathArray); $idx++) { + $file = $filePathArray[$idx]; + if (file_exists($file) == false) { + $body = "File $file not found"; + $result_code = -1; + goto end; + } + $chArr[$idx] = $this->createUploadHandle($url, $filePathArray[$idx]); + + curl_multi_add_handle($mh, $chArr[$idx]); + } + + $running = null; + do { + curl_multi_exec($mh, $running); + } while ($running > 0); + + // Get content and remove handles. + for ($idx = 0; $idx < count($chArr); $idx++) { + $ch = $chArr[$idx]; + + $results[$idx] = curl_multi_getcontent($ch); + + // if request failed. + if (!$results[$idx]) { + $this->http_response = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $body = curl_error($ch); + + //The server successfully processed the request, but is not returning any content. + if ($this->http_response == 204) { + continue; + } + + // HostNotFound, No route to Host, etc Network error + $result_code = -1; + $body = 'CURL Error: = '.$body; + $this->log->addError($body); + } else { + // if request was ok, parsing http response code. + $result_code = $this->http_response = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + // don't check 301, 302 because setting CURLOPT_FOLLOWLOCATION + if ($this->http_response != 200 && $this->http_response != 201) { + $body = 'CURL HTTP Request Failed: Status Code : ' + .$this->http_response.', URL:'.$url + ."\nError Message : ".$response; + $this->log->addError($body); + } + } + } + + // clean up end: - foreach ($chArr as $ch) { - $this->log->addDebug("CURL Close handle.."); - curl_close($ch); - curl_multi_remove_handle($mh, $ch); - } - $this->log->addDebug("CURL Multi Close handle.."); - curl_multi_close($mh); - if ($result_code != 200) { - throw new JIRAException("CURL Error: = " . $body, $result_code); - } - - return $results; - } - - // excerpt from laravel core. - - /** + foreach ($chArr as $ch) { + $this->log->addDebug('CURL Close handle..'); + curl_close($ch); + curl_multi_remove_handle($mh, $ch); + } + $this->log->addDebug('CURL Multi Close handle..'); + curl_multi_close($mh); + if ($result_code != 200) { + throw new JIRAException('CURL Error: = '.$body, $result_code); + } + + return $results; + } + + // excerpt from laravel core. + + /** * Gets the value of an environment variable. Supports boolean, empty and null. * - * @param string $key - * @param mixed $default + * @param string $key + * @param mixed $default + * * @return mixed */ private function env($key, $default = null) { $value = getenv($key); - if ($value === false) return $default; + if ($value === false) { + return $default; + } - switch (strtolower($value)) - { + switch (strtolower($value)) { case 'true': case '(true)': return true; @@ -349,8 +348,7 @@ private function env($key, $default = null) return; } - if ($this->startsWith($value, '"') && endsWith($value, '"')) - { + if ($this->startsWith($value, '"') && endsWith($value, '"')) { return substr($value, 1, -1); } @@ -358,37 +356,40 @@ private function env($key, $default = null) } /** - * Determine if a given string starts with a given substring. - * - * @param string $haystack - * @param string|array $needles - * @return bool - */ - public function startsWith($haystack, $needles) - { - foreach ((array) $needles as $needle) - { - if ($needle != '' && strpos($haystack, $needle) === 0) return true; - } - return false; - } - - /** - * Determine if a given string ends with a given substring. - * - * @param string $haystack - * @param string|array $needles - * @return bool - */ - public function endsWith($haystack, $needles) - { - foreach ((array) $needles as $needle) - { - if ((string) $needle === substr($haystack, -strlen($needle))) return true; - } - return false; - } + * Determine if a given string starts with a given substring. + * + * @param string $haystack + * @param string|array $needles + * + * @return bool + */ + public function startsWith($haystack, $needles) + { + foreach ((array) $needles as $needle) { + if ($needle != '' && strpos($haystack, $needle) === 0) { + return true; + } + } -} + return false; + } -?> \ No newline at end of file + /** + * Determine if a given string ends with a given substring. + * + * @param string $haystack + * @param string|array $needles + * + * @return bool + */ + public function endsWith($haystack, $needles) + { + foreach ((array) $needles as $needle) { + if ((string) $needle === substr($haystack, -strlen($needle))) { + return true; + } + } + + return false; + } +} diff --git a/src/Project/Component.php b/src/Project/Component.php index 94145175..2813e544 100644 --- a/src/Project/Component.php +++ b/src/Project/Component.php @@ -2,30 +2,33 @@ namespace JiraRestApi\Project; -class Component { - /** - * Component URI +class Component +{ + /** + * Component URI. + * * @var string */ public $self; /** - * Component id + * Component id. + * * @var string */ public $id; - /** - * Component name + /** + * Component name. + * * @var string */ public $name; /** - * Component description + * Component description. + * * @var description */ public $description; } - -?> \ No newline at end of file diff --git a/src/Project/Project.php b/src/Project/Project.php index d8b3ff53..eda41d90 100644 --- a/src/Project/Project.php +++ b/src/Project/Project.php @@ -2,47 +2,55 @@ namespace JiraRestApi\Project; -class Project { - /** - * return only if Project query by key(not id) +class Project +{ + /** + * return only if Project query by key(not id). + * * @var string */ - public $expand; + public $expand; - /** - * Project URI + /** + * Project URI. + * * @var string */ public $self; /** - * Project id + * Project id. + * * @var string */ public $id; /** - * Project key - * @var string - */ + * Project key. + * + * @var string + */ public $key; /** - * Project name - * @var string - */ + * Project name. + * + * @var string + */ public $name; /** - * avatar URL - * @var array - */ + * avatar URL. + * + * @var array + */ public $avatarUrls; /** - * Project category - * @var array - */ + * Project category. + * + * @var array + */ public $projectCategory; /* @var string */ @@ -66,5 +74,3 @@ class Project { /* @var array */ public $roles; } - -?> \ No newline at end of file diff --git a/src/Project/ProjectService.php b/src/Project/ProjectService.php index 93c75170..e1992788 100644 --- a/src/Project/ProjectService.php +++ b/src/Project/ProjectService.php @@ -2,42 +2,45 @@ namespace JiraRestApi\Project; -class ProjectService extends \JiraRestApi\JiraClient { - private $uri = "/project"; +class ProjectService extends \JiraRestApi\JiraClient +{ + private $uri = '/project'; - public function __construct() { - parent::__construct(); + public function __construct() + { + parent::__construct(); } /** - * get all project list - * + * get all project list. + * * @return array of Project class */ - public function getAllProjects() { - $ret = $this->exec($this->uri, null); - + public function getAllProjects() + { + $ret = $this->exec($this->uri, null); + $prjs = $this->json_mapper->mapArray( json_decode($ret, true), new \ArrayObject(), '\JiraRestApi\Project\Project' ); - - return $prjs; + + return $prjs; } - /** - * get Project id By Project Key - * + /** + * get Project id By Project Key. + * * @param projectName Project Key(Ex: Test, MyProj) - * + * * @throws HTTPException if the project is not found, or the calling user does not have permission or view it. - * + * * @return string project id - * */ - public function get($projectIdOrKey) { - $ret = $this->exec($this->uri . "/$projectIdOrKey", null); + public function get($projectIdOrKey) + { + $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() diff --git a/tests/CurlTest.php b/tests/CurlTest.php index cc181f17..401b3d8a 100644 --- a/tests/CurlTest.php +++ b/tests/CurlTest.php @@ -2,27 +2,26 @@ use JiraRestApi\HTTPException; -class CurlTest extends PHPUnit_Framework_TestCase +class CurlTest extends PHPUnit_Framework_TestCase { - public function testCurlPost() - { - try { - $config = getHostConfig(); + public function testCurlPost() + { + try { + $config = getHostConfig(); - $config['host']='http://requestb.in/vqid8qvq'; + $config['host'] = 'http://requestb.in/vqid8qvq'; - $j = new \JiraRestApi\JiraClient($config, getOptions()); + $j = new \JiraRestApi\JiraClient($config, getOptions()); - $post_data = array("name" => "value"); + $post_data = array('name' => 'value'); - $http_status = 0; - $ret = $j->exec('/', json_encode($post_data), $http_status); + $http_status = 0; + $ret = $j->exec('/', json_encode($post_data), $http_status); - var_dump($ret); - $this->assertTrue(TRUE); - } catch (HTTPException $e) { - $this->assertTrue(FALSE, $e->getMessage()); - } - } + var_dump($ret); + $this->assertTrue(true); + } catch (HTTPException $e) { + $this->assertTrue(false, $e->getMessage()); + } + } } -?> \ No newline at end of file diff --git a/tests/IssueTest.php b/tests/IssueTest.php index 16e4f368..d6f9b848 100644 --- a/tests/IssueTest.php +++ b/tests/IssueTest.php @@ -5,121 +5,117 @@ use JiraRestApi\Issue\Comment; use JiraRestApi\Issue\Transition; -class IssueTest extends PHPUnit_Framework_TestCase +class IssueTest extends PHPUnit_Framework_TestCase { public function testIssue() { - $this->markTestIncomplete(); - try { - $issueService = new IssueService(); - - $issue = $issueService->get('TEST-867'); - - file_put_contents('jira-issue.json', json_encode($issue, JSON_PRETTY_PRINT)); - - print_r($issue->fields->versions[0]); - - //foreach ($issue->fields->comment->comments as $c) { - // echo ("comment : " . $c->body . "\n"); - //} - - } catch (HTTPException $e) { - $this->assertTrue(FALSE, $e->getMessage()); - } - } - - public function testCreateIssue() + $this->markTestIncomplete(); + try { + $issueService = new IssueService(); + + $issue = $issueService->get('TEST-867'); + + file_put_contents('jira-issue.json', json_encode($issue, JSON_PRETTY_PRINT)); + + print_r($issue->fields->versions[0]); + + //foreach ($issue->fields->comment->comments as $c) { + // echo ("comment : " . $c->body . "\n"); + //} + } catch (HTTPException $e) { + $this->assertTrue(false, $e->getMessage()); + } + } + + public function testCreateIssue() { - try { - $issueField = new IssueField(); - - $issueField->setProjectKey("TEST") - ->setSummary("something's wrong") - ->setAssigneeName("lesstif") - ->setPriorityName("Critical") - ->setIssueType("Bug") - ->setDescription("Full description for issue") - ->addVersion("1.0.1") - ->addVersion("1.0.3") - ; - - $issueService = new IssueService(); - - $ret = $issueService->create($issueField); - - //If success, Returns a link to the created issue. - print_r($ret); - - $issueKey = $ret->{'key'}; - return $issueKey; - } catch (JIRAException $e) { - $this->assertTrue(FALSE, "Create Failed : " . $e->getMessage()); - } - } - // - - /** + try { + $issueField = new IssueField(); + + $issueField->setProjectKey('TEST') + ->setSummary("something's wrong") + ->setAssigneeName('lesstif') + ->setPriorityName('Critical') + ->setIssueType('Bug') + ->setDescription('Full description for issue') + ->addVersion('1.0.1') + ->addVersion('1.0.3') + ; + + $issueService = new IssueService(); + + $ret = $issueService->create($issueField); + + //If success, Returns a link to the created issue. + print_r($ret); + + $issueKey = $ret->{'key'}; + + return $issueKey; + } catch (JIRAException $e) { + $this->assertTrue(false, 'Create Failed : '.$e->getMessage()); + } + } + // + + /** * @depends testCreateIssue - * */ - public function testAddAttachment($issueKey) - { - try { - - $issueService = new IssueService(); + public function testAddAttachment($issueKey) + { + try { + $issueService = new IssueService(); - $ret = $issueService->addAttachments($issueKey, - array('screen_capture.png', 'bug-description.pdf', 'README.md')); + $ret = $issueService->addAttachments($issueKey, + array('screen_capture.png', 'bug-description.pdf', 'README.md')); - print_r($ret); + print_r($ret); - return $issueKey; - } catch (JIRAException $e) { - $this->assertTrue(FALSE, "Attach Failed : " . $e->getMessage()); - } - } + return $issueKey; + } catch (JIRAException $e) { + $this->assertTrue(false, 'Attach Failed : '.$e->getMessage()); + } + } - /** + /** * @depends testAddAttachment - * */ - public function testUpdateIssue($issueKey) + public function testUpdateIssue($issueKey) { - //$this->markTestIncomplete(); - try { - $issueField = new IssueField(true); - - $issueField->setAssigneeName("lesstif") - ->setPriorityName("Major") - ->setIssueType("Task") - ->addLabel("test-label-first") - ->addLabel("test-label-second") - ->addVersion("1.0.1") - ->addVersion("1.0.2") - ->setDescription("This is a shorthand for a set operation on the summary field") - ; - - $issueService = new IssueService(); - - $issueService->update($issueKey, $issueField); - - return $issueKey; - } catch (JIRAException $e) { - $this->assertTrue(FALSE, "update Failed : " . $e->getMessage()); - } - } - - /** + //$this->markTestIncomplete(); + try { + $issueField = new IssueField(true); + + $issueField->setAssigneeName('lesstif') + ->setPriorityName('Major') + ->setIssueType('Task') + ->addLabel('test-label-first') + ->addLabel('test-label-second') + ->addVersion('1.0.1') + ->addVersion('1.0.2') + ->setDescription('This is a shorthand for a set operation on the summary field') + ; + + $issueService = new IssueService(); + + $issueService->update($issueKey, $issueField); + + return $issueKey; + } catch (JIRAException $e) { + $this->assertTrue(false, 'update Failed : '.$e->getMessage()); + } + } + + /** * @depends testUpdateIssue - * */ - public function testAddcomment($issueKey) + public function testAddcomment($issueKey) { - //$this->markTestIncomplete(); - try { - $comment = new Comment(); + //$this->markTestIncomplete(); + try { + $comment = new Comment(); - $body = <<setBody($body) - ->setVisibility('role', 'Users'); - ; + $comment->setBody($body) + ->setVisibility('role', 'Users'); - $issueService = new IssueService(); - $ret = $issueService->addComment($issueKey, $comment); - print_r($ret); + $issueService = new IssueService(); + $ret = $issueService->addComment($issueKey, $comment); + print_r($ret); - return $issueKey; - } catch (JIRAException $e) { - $this->assertTrue(FALSE, "add Comment Failed : " . $e->getMessage()); - } - } + return $issueKey; + } catch (JIRAException $e) { + $this->assertTrue(false, 'add Comment Failed : '.$e->getMessage()); + } + } - /** + /** * @depends testAddcomment - * */ - public function testTransition($issueKey) + public function testTransition($issueKey) { - try { - $transition = new Transition(); - $transition->setTransitionName('Resolved'); - $transition->setCommentBody('Issue close by REST API.'); - - $issueService = new IssueService(); - $ret = $issueService->transition($issueKey, $transition); - - return $issueKey; - } catch (JIRAException $e) { - $this->assertTrue(FALSE, "testTransition Failed : " . $e->getMessage()); - } - } - // + try { + $transition = new Transition(); + $transition->setTransitionName('Resolved'); + $transition->setCommentBody('Issue close by REST API.'); + + $issueService = new IssueService(); + $ret = $issueService->transition($issueKey, $transition); + + return $issueKey; + } catch (JIRAException $e) { + $this->assertTrue(false, 'testTransition Failed : '.$e->getMessage()); + } + } + // } - -?> diff --git a/tests/ProjectTest.php b/tests/ProjectTest.php index f4f6daf9..45efbb6a 100644 --- a/tests/ProjectTest.php +++ b/tests/ProjectTest.php @@ -2,44 +2,41 @@ use JiraRestApi\Project\ProjectService; -class ProjectTest extends PHPUnit_Framework_TestCase +class ProjectTest extends PHPUnit_Framework_TestCase { public function testGetProject() { - //$this->markTestIncomplete(); - try { - $proj = new ProjectService(); + //$this->markTestIncomplete(); + try { + $proj = new ProjectService(); - $p = $proj->get('TEST'); - - print_r($p->lead); - foreach ($p->components as $c) { - echo ("COM : " . $c->name . "\n"); - } - } catch (HTTPException $e) { - $this->assertTrue(FALSE, $e->getMessage()); - } - } + $p = $proj->get('TEST'); - public function testGetProjectLists() + print_r($p->lead); + foreach ($p->components as $c) { + echo('COM : '.$c->name."\n"); + } + } catch (HTTPException $e) { + $this->assertTrue(false, $e->getMessage()); + } + } + + public function testGetProjectLists() { - //$this->markTestIncomplete(); - try { - $proj = new ProjectService(); + //$this->markTestIncomplete(); + try { + $proj = new ProjectService(); - $prjs = $proj->getAllProjects(); + $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()); - } - } - // + 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()); + } + } + // } - -?> diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 3b2c5f3c..db9264ea 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -8,9 +8,7 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -$loader = require __DIR__ . "/../vendor/autoload.php"; +$loader = require __DIR__.'/../vendor/autoload.php'; $loader->addPsr4('JiraRestApi\\', __DIR__); date_default_timezone_set('UTC'); - -?>