diff --git a/src/Adapter.php b/src/Adapter.php index d40d50a..445a3db 100644 --- a/src/Adapter.php +++ b/src/Adapter.php @@ -1,4 +1,6 @@ -warning( - "The project config for {$this->getHook()->getProjectName()} " . + "The project config for {$this->getHook()->getProjectName()} ". "doesn't enable to run the job when the build failed" ); @@ -85,7 +87,7 @@ public function run() } /** - * Load the rundeck job runner + * Load the rundeck job runner. * * @param JobRunner $jobRunner */ @@ -99,7 +101,7 @@ public function attachJobRunner(JobRunner $jobRunner) } /** - * Load the projects config + * Load the projects config. * * @param ProjectConfig $projectsConfig */ @@ -131,7 +133,7 @@ private function getJobRunner() } /** - * Get the hook + * Get the hook. * * @return HookResolver */ @@ -140,14 +142,14 @@ private function getHook() if (!isset($this->hook)) { $this->hook = HookResolver::load($this->getInput()); - $this->debug('Hook handler type: ' . get_class($this->hook)); + $this->debug('Hook handler type: '.get_class($this->hook)); } return $this->hook; } /** - * Get the input (php://input by default) + * Get the input (php://input by default). * * @return string */ @@ -158,7 +160,7 @@ private function getInput() $this->input = file_get_contents('php://input'); - $this->debug('input content: ' . $this->input); + $this->debug('input content: '.$this->input); } return $this->input; @@ -175,13 +177,13 @@ public function setInput($input) } /** - * Call the logger + * Call the logger. * * @param $level * @param $message * @param array $context */ - public function log($level, $message, array $context = array()) + public function log($level, $message, array $context = []) { if ($this->logger) { $this->logger->log($level, $message, $context); diff --git a/src/Config/AbstractConfig.php b/src/Config/AbstractConfig.php index ed54ca9..1d2541f 100644 --- a/src/Config/AbstractConfig.php +++ b/src/Config/AbstractConfig.php @@ -1,4 +1,6 @@ - [ 'header' => "X-Rundeck-Auth-Token: {$this->config['token']}\r\n", - 'method' => $method - ] + 'method' => $method, + ], ]; if ($method == 'POST') { - $options ['http']['header'] .= "Content-type: application/x-www-form-urlencoded\r\n"; - $options ['http']['content'] = http_build_query($parameters); + $options['http']['header'] .= "Content-type: application/x-www-form-urlencoded\r\n"; + $options['http']['content'] = http_build_query($parameters); } $context = stream_context_create($options); @@ -50,7 +52,7 @@ public function run($jobId, array $parameters = []) } /** - * Return the formatted url for a GET or POST rundeck request to run a job + * Return the formatted url for a GET or POST rundeck request to run a job. * * http://rundeck.org/docs/api/index.html#running-a-job * GET /api/1/job/[ID]/run @@ -59,15 +61,16 @@ public function run($jobId, array $parameters = []) * @param $jobId * @param string $method * - * @return string * @throws Exception + * + * @return string */ public function getApiUrl($jobId, $method = 'GET') { return - "http" . (($this->config['ssl']) ? 's' : '') . "://" . - $this->config['host'] . ':' . $this->config['port'] . '/api/' . - $this->config['api_version'] . '/job/' . $jobId . '/' . + 'http'.(($this->config['ssl']) ? 's' : '').'://'. + $this->config['host'].':'.$this->config['port'].'/api/'. + $this->config['api_version'].'/job/'.$jobId.'/'. ((strcasecmp($method, 'get') == 0) ? 'run' : 'executions'); } } diff --git a/tests/G2R/AdapterTest.php b/tests/G2R/AdapterTest.php index e429a08..6f4b3da 100644 --- a/tests/G2R/AdapterTest.php +++ b/tests/G2R/AdapterTest.php @@ -1,6 +1,6 @@ -disableOriginalConstructor() ->setMethods([ 'getApiUrl', - 'getFilename' + 'getFilename', ]) ->getMock(); @@ -206,7 +206,7 @@ private function mockJobRunner($rundeckConfig) ->disableOriginalConstructor() ->setMethods([ 'getConfig', - 'run' + 'run', ]) ->getMock(); @@ -222,7 +222,7 @@ private function mockProjectsConfig() ->disableOriginalConstructor() ->setMethods([ 'getProject', - 'getFilename' + 'getFilename', ]) ->getMock(); @@ -237,10 +237,10 @@ private function getProjectThatRunOnFail() 'ref' => 'master', 'runOnFail' => true, 'runOnTagOnly' => true, - 'jobArgs' => array( + 'jobArgs' => [ 'arg1' => 'foo', 'arg2' => 'bar', - ), + ], 'runJobAs' => 'foo', ]; } @@ -253,10 +253,10 @@ private function getProjectThatDoesNotRunOnFail() 'ref' => 'master', 'runOnFail' => false, 'runOnTagOnly' => true, - 'jobArgs' => array( + 'jobArgs' => [ 'arg1' => 'foo', 'arg2' => 'bar', - ), + ], 'runJobAs' => 'foo', ]; } diff --git a/tests/G2R/Config/ProjectConfigTest.php b/tests/G2R/Config/ProjectConfigTest.php index 00ce1cb..9d128bd 100644 --- a/tests/G2R/Config/ProjectConfigTest.php +++ b/tests/G2R/Config/ProjectConfigTest.php @@ -1,4 +1,6 @@ -assertEquals( [ - 'name' => 'repos/app1', - 'jobId' => '558d3c76-7768-4056-a10c-0842ecae0ca9', - 'ref' => 'master', - 'runOnFail' => true, + 'name' => 'repos/app1', + 'jobId' => '558d3c76-7768-4056-a10c-0842ecae0ca9', + 'ref' => 'master', + 'runOnFail' => true, 'runOnTagOnly' => true, - 'jobArgs' => array ( + 'jobArgs' => [ 'arg1' => 'foo', 'arg2' => 'bar', - ), + ], 'runJobAs' => 'foo', - 'filter' => 'stagging', + 'filter' => 'stagging', ], $this->config->getProject('repos/app1') ); diff --git a/tests/G2R/Config/RundeckConfigTest.php b/tests/G2R/Config/RundeckConfigTest.php index ecd7366..b4510ad 100644 --- a/tests/G2R/Config/RundeckConfigTest.php +++ b/tests/G2R/Config/RundeckConfigTest.php @@ -1,4 +1,6 @@ -assertEquals( $RunningJobApiPost, - $jobRunner->getApiUrl($jobId, "POST") + $jobRunner->getApiUrl($jobId, 'POST') ); // check the method isn't case sensitive $this->assertEquals( $RunningJobApiPost, - $jobRunner->getApiUrl($jobId, "pOsT") + $jobRunner->getApiUrl($jobId, 'pOsT') ); } } diff --git a/tests/G2R/TestCase.php b/tests/G2R/TestCase.php index edb949e..5a7cb19 100644 --- a/tests/G2R/TestCase.php +++ b/tests/G2R/TestCase.php @@ -1,4 +1,6 @@ -dataFolder = dirname(__DIR__) . "/data"; + $this->dataFolder = dirname(__DIR__).'/data'; } protected function loadFile($file) @@ -18,6 +20,6 @@ protected function loadFile($file) protected function locate($file) { - return dirname(__DIR__) . "/data/{$file}"; + return dirname(__DIR__)."/data/{$file}"; } }