diff --git a/README.md b/README.md index 8d4439b6..8a17cac1 100644 --- a/README.md +++ b/README.md @@ -5,27 +5,18 @@ composer require lesstif/php-jira-rest-client dev-master ``` -create config.jira.php file on your project root. -````php - 'https://jira.example.com', - 'username' => 'username', - 'password' => 'password', - - // Options - 'CURLOPT_SSL_VERIFYHOST' => false, - 'CURLOPT_SSL_VERIFYPEER' => false, - 'CURLOPT_VERBOSE' => true, - 'LOG_FILE' => 'jira-rest-client.log', - 'LOG_LEVEL' => 'DEBUG' - ); +create config.jira.json file on your project root. +````json +{ + "host": "https://jira.example.com", + "username": "username", + "password": "password", + "CURLOPT_SSL_VERIFYHOST": false, + "CURLOPT_SSL_VERIFYPEER": false, + "CURLOPT_VERBOSE": false, + "LOG_FILE": "jira-rest-client.log", + "LOG_LEVEL": "DEBUG" } - -?> ```` # Usage @@ -35,7 +26,6 @@ function getConfig() { ````php =5.4.0", "netresearch/jsonmapper": "0.4.*", - "monolog/monolog": "~1.12" + "monolog/monolog": "~1.12", + "noodlehaus/config": "0.7.*" }, "require-dev": { "phpunit/phpunit": "~4.4" diff --git a/phpunit.xml b/phpunit.xml index a396563d..bd979be3 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -3,11 +3,7 @@ - - tests/ProjectTest.php - tests/IssueTest.php diff --git a/src/JiraClient.php b/src/JiraClient.php index df7c7b1b..79c98392 100644 --- a/src/JiraClient.php +++ b/src/JiraClient.php @@ -9,6 +9,8 @@ class JIRAException extends \Exception { } use \Monolog\Logger as Logger; use \Monolog\Handler\StreamHandler; +use \Noodlehaus\Config as Config; + /** * interact jira server with REST API */ @@ -43,8 +45,8 @@ class JiraClient { // debug curl protected $CURLOPT_VERBOSE = false; - protected $LOG_FILE = 'jira-rest-client.log'; - protected $LOG_LEVEL = Logger::INFO; + protected $LOG_FILE; + protected $LOG_LEVEL; private function convertLogLevel($log_level) { if ($log_level == 'DEBUG') @@ -75,8 +77,10 @@ protected function filterNullVariable($haystack) return $haystack; } - public function __construct($config) - { + public function __construct() + { + $config = Config::load('config.jira.json'); + $this->json_mapper = new \JsonMapper(); $this->json_mapper->bExceptionOnUndefinedProperty = true; @@ -84,20 +88,13 @@ public function __construct($config) $this->username = $config['username']; $this->password = $config['password']; - if (isset($config['CURLOPT_SSL_VERIFYHOST'])) - $this->CURLOPT_SSL_VERIFYHOST = $config['CURLOPT_SSL_VERIFYHOST'] === true ? true: false; - - if (isset($config['CURLOPT_SSL_VERIFYPEER'])) - $this->CURLOPT_SSL_VERIFYPEER = $config['CURLOPT_SSL_VERIFYPEER'] === true ? true: false; + $this->CURLOPT_SSL_VERIFYHOST = $config->get('CURLOPT_SSL_VERIFYHOST', false); - if (isset($config['CURLOPT_VERBOSE'])) - $this->CURLOPT_VERBOSE = $config['CURLOPT_VERBOSE'] === true ? true: false; + $this->CURLOPT_SSL_VERIFYPEER = $config->get('CURLOPT_SSL_VERIFYPEER', false); + $this->CURLOPT_VERBOSE = $config->get('CURLOPT_VERBOSE', false); - if (isset($config['LOG_FILE'])) - $this->LOG_FILE = $config['LOG_FILE']; - - if (isset($config['LOG_LEVEL'])) - $this->LOG_LEVEL = $this->convertLogLevel($config['LOG_LEVEL']); + $this->LOG_FILE = $config->get('LOG_FILE', 'jira-rest-client.log'); + $this->LOG_LEVEL = $this->convertLogLevel($config->get('LOG_LEVEL', Logger::INFO)); // create logger $this->log = new Logger('JiraClient'); @@ -193,11 +190,11 @@ public function upload($context, $upload_file) { curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $url); - /* - $attachments = array( - 'file' => '@' . realpath($upload_file) - ); + /* CURLFile support PHP 5.5 + $cf = new \CURLFile(realpath($upload_file), 'image/png', $upload_file); + $this->log->addDebug('CURLFile=' . var_export($cf, true)); */ + $attachments = realpath($upload_file); $filename = basename($upload_file); diff --git a/src/config.jira.example.json b/src/config.jira.example.json new file mode 100644 index 00000000..ed5664a5 --- /dev/null +++ b/src/config.jira.example.json @@ -0,0 +1,10 @@ +{ + "host": "https://jira.example.com", + "username": "username", + "password": "password", + "CURLOPT_SSL_VERIFYHOST": false, + "CURLOPT_SSL_VERIFYPEER": false, + "CURLOPT_VERBOSE": false, + "LOG_FILE": "jira-rest-client.log", + "LOG_LEVEL": "DEBUG" +} diff --git a/src/issue/IssueService.php b/src/issue/IssueService.php index 40bb35d4..eebda2d5 100644 --- a/src/issue/IssueService.php +++ b/src/issue/IssueService.php @@ -6,7 +6,7 @@ class IssueService extends \JiraRestApi\JiraClient { private $uri = "/issue"; public function __construct() { - parent::__construct(getConfig()); + parent::__construct(); } /** diff --git a/src/project/ProjectService.php b/src/project/ProjectService.php index 8a5def2e..93c75170 100644 --- a/src/project/ProjectService.php +++ b/src/project/ProjectService.php @@ -6,7 +6,7 @@ class ProjectService extends \JiraRestApi\JiraClient { private $uri = "/project"; public function __construct() { - parent::__construct(getConfig()); + parent::__construct(); } /** diff --git a/tests/IssueTest.php b/tests/IssueTest.php index 0e190cdd..49ec1135 100644 --- a/tests/IssueTest.php +++ b/tests/IssueTest.php @@ -2,7 +2,6 @@ use JiraRestApi\Issue\IssueService; use JiraRestApi\Issue\IssueField; -use JiraRestApi\Issue\Comment; class IssueTest extends PHPUnit_Framework_TestCase { @@ -29,7 +28,6 @@ public function testIssue() public function testCreateIssue() { - $this->markTestIncomplete(); try { $issueField = new IssueField(); @@ -63,8 +61,7 @@ public function testCreateIssue() * */ public function testAddAttachment($issueKey) - { - $this->markTestIncomplete(); + { try { $issueService = new IssueService(); @@ -85,7 +82,7 @@ public function testAddAttachment($issueKey) */ public function testUpdateIssue($issueKey) { - $this->markTestIncomplete(); + //$this->markTestIncomplete(); try { $issueField = new IssueField(true); @@ -102,42 +99,11 @@ public function testUpdateIssue($issueKey) $issueService = new IssueService(); $issueService->update($issueKey, $issueField); - - return $issueKey; } catch (JIRAException $e) { $this->assertTrue(FALSE, "update Failed : " . $e->getMessage()); } } - /** - * Depends testUpdateIssue - * - */ - public function testAddcommnet() - { - $issueKey = "TEST-924"; - //$this->markTestIncomplete(); - try { - $comment = new Comment(); - - $body = <<setBody($body) - ->setVisibility('role', 'Users'); - ; - - $issueService = new IssueService(); - $ret = $issueService->addComment($issueKey, $comment); - print_r($ret); - } catch (JIRAException $e) { - $this->assertTrue(FALSE, "add Comment Failed : " . $e->getMessage()); - } - } } ?> diff --git a/tests/ProjectTest.php b/tests/ProjectTest.php index cc02d70e..f4f6daf9 100644 --- a/tests/ProjectTest.php +++ b/tests/ProjectTest.php @@ -29,7 +29,6 @@ public function testGetProjectLists() $prjs = $proj->getAllProjects(); - $i = 0; 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'] diff --git a/tests/bootstrap.php b/tests/bootstrap.php index f22039e5..3b2c5f3c 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -11,8 +11,6 @@ $loader = require __DIR__ . "/../vendor/autoload.php"; $loader->addPsr4('JiraRestApi\\', __DIR__); -require_once __DIR__ . '/../config.jira.php'; - date_default_timezone_set('UTC'); -?> \ No newline at end of file +?>