diff --git a/README.md b/README.md index 3cad8a8..3c81736 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,15 @@ curl -sS https://getcomposer.org/installer | php Then, run the Composer command to install the latest version: ```bash -composer.phar require jenkins-khan/jenkins-api +composer.phar require didungar/jenkins-api ``` +On error "minimum-stability" declare repository : +```json +"repositories": [ + { "type": "vcs", "url": "https://github.com/didungar/jenkins-php-api" } + ], +``` Basic Usage ----------- @@ -28,7 +34,7 @@ Before anything, you need to instantiate the client : ```php - $jenkins = new \JenkinsKhan\Jenkins('http://host.org:8080'); + $jenkins = new \DidUngar\Jenkins('http://host.org:8080'); ``` If your Jenkins needs authentication, you need to pass a URL like this : `'http://user:token@host.org:8080'`. diff --git a/composer.json b/composer.json index 98dd920..5018933 100644 --- a/composer.json +++ b/composer.json @@ -1,13 +1,16 @@ { - "name": "jenkins-khan/jenkins-api", + "name": "didungar/jenkins-api", "type": "library", "description": "Jenkins PHP API", - "keywords": ["jenkins", "api"], - "homepage": "https://github.com/jenkins-khan/jenkins-php-api", + "keywords": [ + "jenkins", + "api" + ], + "homepage": "https://github.com/didungar/jenkins-php-api", "license": "MIT", "autoload": { "psr-4": { - "JenkinsKhan\\": "src/" + "DidUngar\\": "src/" } }, "require-dev": { @@ -18,8 +21,8 @@ }, "authors": [ { - "name": "jenkins-khan", - "homepage": "https://github.com/jenkins-khan/jenkins-php-api" + "name": "didungar", + "homepage": "https://github.com/didungar/jenkins-php-api" } ] } diff --git a/src/Jenkins.php b/src/Jenkins.php index d91d4e3..65bb6d9 100755 --- a/src/Jenkins.php +++ b/src/Jenkins.php @@ -1,6 +1,6 @@ validateCurl( $curl, - sprintf( 'Error during getting information for executors[%s@%s] on %s', $i, $computer, $this->baseUrl) + sprintf('Error during getting information for executors[%s@%s] on %s', $i, $computer, $this->baseUrl) ); $infos = json_decode($ret); @@ -270,7 +270,7 @@ public function launchJob($jobName, $parameters = array()) /** * @param string $jobName * - * @return bool|\JenkinsKhan\Jenkins\Job + * @return bool|\DidUngar\Jenkins\Job * @throws \RuntimeException */ public function getJob($jobName) @@ -619,7 +619,10 @@ public function getJobConfig($jobname) public function stopExecutor(Jenkins\Executor $executor) { $url = sprintf( - '%s/computer/%s/executors/%s/stop', $this->baseUrl, $executor->getComputer(), $executor->getNumber() + '%s/computer/%s/executors/%s/stop', + $this->baseUrl, + $executor->getComputer(), + $executor->getNumber() ); $curl = curl_init($url); @@ -666,7 +669,6 @@ public function cancelQueue(Jenkins\JobQueue $queue) $curl, sprintf('Error during stopping job queue #%s', $queue->getId()) ); - } /** @@ -749,7 +751,10 @@ public function getTestReport($jobName, $buildId) $ret = curl_exec($curl); $errorMessage = sprintf( - 'Error during getting information for build %s#%d on %s', $jobName, $buildId, $this->baseUrl + 'Error during getting information for build %s#%d on %s', + $jobName, + $buildId, + $this->baseUrl ); $this->validateCurl( @@ -794,7 +799,8 @@ public function execute($uri, array $curlOptions) public function getComputers() { $return = $this->execute( - '/computer/api/json', array( + '/computer/api/json', + array( \CURLOPT_RETURNTRANSFER => 1, ) ); @@ -826,8 +832,8 @@ public function getComputerConfiguration($computerName) * @param $curl * @param $errorMessage */ - private function validateCurl($curl, $errorMessage) { - + private function validateCurl($curl, $errorMessage) + { if (curl_errno($curl)) { throw new \RuntimeException($errorMessage); } diff --git a/src/Jenkins/Build.php b/src/Jenkins/Build.php index 0e87469..2b72938 100755 --- a/src/Jenkins/Build.php +++ b/src/Jenkins/Build.php @@ -1,8 +1,8 @@ mockGenerator->generate('\Jenkins'); - return true; - } - - public function test__construct() - { - $jenkins = new \mock\JenkinsKhan\Jenkins('url'); - - $reportJson = json_decode(file_get_contents(__DIR__ . '/report_passed.json')); - $report = new \JenkinsKhan\Jenkins\TestReport($jenkins, $reportJson, $jobName = 'units', $buildNumber = '32'); - $this->assert->variable($report->getJobName())->isEqualTo($jobName); - $this->assert->variable($report->getBuildNumber())->isEqualTo($buildNumber); - $this->assert->float($report->getDuration())->isEqualTo(0.3716328); - $this->assert->integer($report->getFailCount())->isEqualTo(0); - $this->assert->integer($report->getSkipCount())->isEqualTo(0); - $this->assert->integer($report->getPassCount())->isEqualTo(9); - $this->assert->phpArray($report->getSuites())->hasSize(4); - } - - public function test_getOriginalTestReport() - { - $jenkins = new \mock\JenkinsKhan\Jenkins('url'); - - $reportJson = json_decode(file_get_contents(__DIR__ . '/report_passed.json')); - $report = new \JenkinsKhan\Jenkins\TestReport($jenkins, $reportJson, $jobName = 'units', $buildNumber = '32'); - - $this->assert->string($report = $report->getOriginalTestReport()) + public function setUp() + { + $this->mockGenerator->generate('\Jenkins'); + return true; + } + + public function test__construct() + { + $jenkins = new \mock\DidUngar\Jenkins('url'); + + $reportJson = json_decode(file_get_contents(__DIR__ . '/report_passed.json')); + $report = new \DidUngar\Jenkins\TestReport($jenkins, $reportJson, $jobName = 'units', $buildNumber = '32'); + $this->assert->variable($report->getJobName())->isEqualTo($jobName); + $this->assert->variable($report->getBuildNumber())->isEqualTo($buildNumber); + $this->assert->float($report->getDuration())->isEqualTo(0.3716328); + $this->assert->integer($report->getFailCount())->isEqualTo(0); + $this->assert->integer($report->getSkipCount())->isEqualTo(0); + $this->assert->integer($report->getPassCount())->isEqualTo(9); + $this->assert->phpArray($report->getSuites())->hasSize(4); + } + + public function test_getOriginalTestReport() + { + $jenkins = new \mock\DidUngar\Jenkins('url'); + + $reportJson = json_decode(file_get_contents(__DIR__ . '/report_passed.json')); + $report = new \DidUngar\Jenkins\TestReport($jenkins, $reportJson, $jobName = 'units', $buildNumber = '32'); + + $this->assert->string($report = $report->getOriginalTestReport()) ->isNotEmpty() ->hasLength(2528) ->contains('"failCount":0') ->contains('"passCount":9') ; - $this->assert->array(json_decode($report, true)) + $this->assert->array(json_decode($report, true)) ->isNotEmpty() ->hasSize(5) ; - } - - public function test_getSuite() - { - $jenkins = new \mock\JenkinsKhan\Jenkins('url'); - - $reportJson = json_decode(file_get_contents(__DIR__ . '/report_passed.json')); - $report = new \JenkinsKhan\Jenkins\TestReport($jenkins, $reportJson, $jobName = 'units', $buildNumber = '32'); - - $this->assert->object($suite = $report->getSuite(0))->isInstanceOf('stdClass'); - $this->assert->phpArray($suite->cases)->hasSize(1); - $this->assert->float($suite->duration)->isEqualTo(0.06950712); - } - - /** - * @dataProvider getSuiteStatusDataProvider - */ - public function testGetSuiteStatusDataProvider($file, $suiteId, $status) - { - $jenkins = new \mock\JenkinsKhan\Jenkins('url'); - - $reportJson = json_decode(file_get_contents(__DIR__ . '/' . $file)); - $report = new \JenkinsKhan\Jenkins\TestReport($jenkins, $reportJson, $jobName = 'units', $buildNumber = '32'); - - $this->assert->string($suite = $report->getSuiteStatus($suiteId))->isEqualTo($status); - } - - /** - * @return array - */ - public function getSuiteStatusDataProvider() - { - //file - suiteid - status - return array( + } + + public function test_getSuite() + { + $jenkins = new \mock\DidUngar\Jenkins('url'); + + $reportJson = json_decode(file_get_contents(__DIR__ . '/report_passed.json')); + $report = new \DidUngar\Jenkins\TestReport($jenkins, $reportJson, $jobName = 'units', $buildNumber = '32'); + + $this->assert->object($suite = $report->getSuite(0))->isInstanceOf('stdClass'); + $this->assert->phpArray($suite->cases)->hasSize(1); + $this->assert->float($suite->duration)->isEqualTo(0.06950712); + } + + /** + * @dataProvider getSuiteStatusDataProvider + */ + public function testGetSuiteStatusDataProvider($file, $suiteId, $status) + { + $jenkins = new \mock\DidUngar\Jenkins('url'); + + $reportJson = json_decode(file_get_contents(__DIR__ . '/' . $file)); + $report = new \DidUngar\Jenkins\TestReport($jenkins, $reportJson, $jobName = 'units', $buildNumber = '32'); + + $this->assert->string($suite = $report->getSuiteStatus($suiteId))->isEqualTo($status); + } + + /** + * @return array + */ + public function getSuiteStatusDataProvider() + { + //file - suiteid - status + return array( array('report_passed.json', 0, 'PASSED'), array('report_passed.json', 1, 'PASSED'), array('report_passed.json', 2, 'PASSED'), @@ -91,6 +90,5 @@ public function getSuiteStatusDataProvider() array('report_failed.json', 2, 'PASSED'), array('report_failed.json', 3, 'PASSED'), ); - } - + } }