From 6bed12820d52c742e910f03bffcbed499d70c21b Mon Sep 17 00:00:00 2001 From: guillermo-fisher Date: Fri, 31 Oct 2014 09:56:52 -0400 Subject: [PATCH 01/11] Added the ManagementConsole class. --- .../Api/Enterprise/ManagementConsole.php | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 lib/Github/Api/Enterprise/ManagementConsole.php diff --git a/lib/Github/Api/Enterprise/ManagementConsole.php b/lib/Github/Api/Enterprise/ManagementConsole.php new file mode 100644 index 00000000000..2c61ccddeee --- /dev/null +++ b/lib/Github/Api/Enterprise/ManagementConsole.php @@ -0,0 +1,80 @@ +get('/setup/api/configcheck', $hash); + } + + /** + * Retrieves your installation’s settings. + * @link https://developer.github.com/v3/enterprise/management_console/#retrieve-settings + * + * @param string $hash md5 hash of your license + * @return array array of settings + */ + public function settings($hash) + { + return $this->get('/setup/api/settings', $hash); + } + + /** + * Checks your installation’s maintenance status. + * @link https://developer.github.com/v3/enterprise/management_console/#check-maintenance-status + * + * @param string $hash md5 hash of your license + * @return array array of maintenance status information + */ + public function maintenance($hash) + { + return $this->get('/setup/api/maintenance', $hash); + } + + /** + * Retrieves your installation’s authorized SSH keys. + * @link https://developer.github.com/v3/enterprise/management_console/#retrieve-authorized-ssh-keys + * + * @param string $hash md5 hash of your license + * @return array array of authorized keys + */ + public function keys($hash) + { + return $this->get('/setup/api/settings/authorized-keys', $hash); + } + + public function getClient() + { + return $this->client; + } + + /** + * Sends an authenticated GET request. + * + * @see \Github\Api\AbstractApi::get() + * @param string $uri + * @param array $hash + * @return \Guzzle\Http\EntityBodyInterface|mixed|string + */ + protected function get($uri, $hash) + { + return parent::get($uri, array('auth' => array('license', rawurlencode($hash)))); + } +} From de4eeb4e79d410cb38569ddd230c622db0cbfd24 Mon Sep 17 00:00:00 2001 From: guillermo-fisher Date: Fri, 31 Oct 2014 09:57:43 -0400 Subject: [PATCH 02/11] Added a convenience method to the Enterprise class. --- lib/Github/Api/Enterprise.php | 9 +++++++++ test/Github/Tests/Api/EnterpriseTest.php | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/Github/Api/Enterprise.php b/lib/Github/Api/Enterprise.php index 38e7cbff44c..48f90f06b27 100644 --- a/lib/Github/Api/Enterprise.php +++ b/lib/Github/Api/Enterprise.php @@ -2,6 +2,7 @@ namespace Github\Api; +use Github\Api\Enterprise\ManagementConsole; use Github\Api\Enterprise\Stats; use Github\Api\Enterprise\License; @@ -29,4 +30,12 @@ public function license() { return new License($this->client); } + + /** + * @return ManagementConsole + */ + public function console() + { + return new ManagementConsole($this->client); + } } diff --git a/test/Github/Tests/Api/EnterpriseTest.php b/test/Github/Tests/Api/EnterpriseTest.php index 399ecd78e67..ad21b9aa167 100644 --- a/test/Github/Tests/Api/EnterpriseTest.php +++ b/test/Github/Tests/Api/EnterpriseTest.php @@ -30,9 +30,18 @@ public function shouldGetEnterpriseLicenseApiObject() $this->assertInstanceOf('Github\Api\Enterprise\License', $api->license()); } + /** + * @test + */ + public function shouldGetEnterpriseManagementConsoleApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf('Github\Api\Enterprise\ManagementConsole', $api->console()); + } + protected function getApiClass() { return 'Github\Api\Enterprise'; } } - From 944ef805a60b39b44eb1ee668333450644afb02d Mon Sep 17 00:00:00 2001 From: guillermo-fisher Date: Fri, 31 Oct 2014 09:58:05 -0400 Subject: [PATCH 03/11] Added ManagementConsole tests. --- .../Api/Enterprise/ManagementConsoleTest.php | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php diff --git a/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php b/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php new file mode 100644 index 00000000000..8d222b65360 --- /dev/null +++ b/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php @@ -0,0 +1,121 @@ +getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/setup/api/configcheck') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->configcheck($this->getLicenseHash())); + } + + /** + * @test + */ + public function shouldShowSettingsData() + { + $expectedJson = '{ "enterprise": { "private_mode": false, "github_hostname": "ghe.local", "auth_mode": + "default", "storage_mode": "rootfs", "admin_password": null, "configuration_id": 1401777404, + "configuration_run_count": 4, "package_version": "11.10.332", "avatar": { "enabled": false, "uri": "" }, + "customer": { "name": "GitHub", "email": "stannis@themannis.biz", "uuid": + "af6cac80-e4e1-012e-d822-1231380e52e9", + "secret_key_data": "-----BEGIN PGP PRIVATE KEY BLOCK-----\nVersion: GnuPG v1.4.10 (GNU/Linux)\n\nlQcYBE5TCgsBEACk4yHpUcapplebaumBMXYMiLF+nCQ0lxpx...\n-----END PGP PRIVATE KEY BLOCK-----\n", + "public_key_data": "-----BEGIN PGP PUBLIC KEY BLOCK-----\nVersion: GnuPG v1.4.10 (GNU/Linux)\n\nmI0ETqzZYgEEALSe6snowdenXyqvLfSQ34HWD6C7....\n-----END PGP PUBLIC KEY BLOCK-----\n" }, + "license": { "seats": 0, "evaluation": false, "expire_at": "2015-04-27T00:00:00-07:00", "perpetual": false, + "unlimited_seating": true, "support_key": "ssh-rsa AAAAB3N....", "ssh_allowed": true }, "github_ssl": + { "enabled": false, "cert": null, "key": null }, "ldap": { "host": "", "port": "", "base": [ ], "uid": "", + "bind_dn": "", "password": "", "method": "Plain", "user_groups": [ ], "admin_group": "" }, "cas": { "url": "" }, + "github_oauth": { "client_id": "12313412", "client_secret": "kj123131132", "organization_name": + "Homestar Runners", "organization_team": "homestarrunners/owners" }, "smtp": { "enabled": true, "address": + "smtp.example.com", "authentication": "plain", "port": "1234", "domain": "blah", "username": "foo", "user_name": + "mr_foo", "enable_starttls_auto": true, "password": "bar", "support_address": "enterprise@github.com", + "noreply_address": "noreply@github.com" }, "dns": { "primary_nameserver": "8.8.8.8", "secondary_nameserver": + "8.8.4.4" }, "ntp": { "primary_server": "0.ubuntu.pool.ntp.org", "secondary_server": "1.ubuntu.pool.ntp.org" }, + "timezone": { "identifier": "UTC" }, "device": { "path": "/dev/xyz" }, "snmp": { "enabled": false, + "community": "" }, "rsyslog": { "enabled": false, "server": "", "protocol_name": "TCP" }, "assets": { "storage": + "file", "bucket": null, "host_name": null, "key_id": null, "access_key": null }, "pages": { "enabled": true }, + "collectd": { "enabled": false, "server": "", "port": "", "encryption": "", "username": "foo", "password": + "bar" } }, "run_list": [ "role[configure]" ] }'; + $expectedArray = json_encode($expectedJson); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/setup/api/settings') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->settings($this->getLicenseHash())); + } + + /** + * @test + */ + public function shouldShowMaintenanceStatus() + { + $expectedJson = '{ "status": "scheduled", "scheduled_time": "Tuesday, January 22 at 15 => 34 -0800", + "connection_services": [ { "name": "git operations", "number": 0 }, { "name": "mysql queries", "number": 233 }, + { "name": "resque jobs", "number": 54 } ] }'; + $expectedArray = json_encode($expectedJson); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/setup/api/maintenance') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->maintenance($this->getLicenseHash())); + } + + /** + * @test + */ + public function shouldShowAuthorizedKeys() + { + $expectedJson = '[ { "key": "ssh-rsa AAAAB3NzaC1yc2EAAAAB...", "pretty-print": + "ssh-rsa 01:14:0f:f2:0f:e2:fe:e8:f4:72:62:af:75:f7:1a:88:3e:04:92:64" }, + { "key": "ssh-rsa AAAAB3NzaC1yc2EAAAAB...", "pretty-print": + "ssh-rsa 01:14:0f:f2:0f:e2:fe:e8:f4:72:62:af:75:f7:1a:88:3e:04:92:64" } ]'; + $expectedArray = json_encode($expectedJson); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/setup/api/settings/authorized-keys') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->keys($this->getLicenseHash())); + } + + protected function getLicenseHash() + { + return '1234567890abcdefghijklmnopqrstuv'; + } + + protected function getApiClass() + { + return 'Github\Api\Enterprise\ManagementConsole'; + } +} From a6031261f8b8cb31589337c68a027a861a076b01 Mon Sep 17 00:00:00 2001 From: guillermo-fisher Date: Fri, 31 Oct 2014 09:58:28 -0400 Subject: [PATCH 04/11] Back-filled other Enterprise tests. --- .../Tests/Api/Enterprise/LicenseTest.php | 42 ++++++++++++++++ .../Github/Tests/Api/Enterprise/StatsTest.php | 49 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 test/Github/Tests/Api/Enterprise/LicenseTest.php create mode 100644 test/Github/Tests/Api/Enterprise/StatsTest.php diff --git a/test/Github/Tests/Api/Enterprise/LicenseTest.php b/test/Github/Tests/Api/Enterprise/LicenseTest.php new file mode 100644 index 00000000000..3b10c34dad4 --- /dev/null +++ b/test/Github/Tests/Api/Enterprise/LicenseTest.php @@ -0,0 +1,42 @@ + 1400, + 'seats_used' => 1316, + 'seats_available' => 84, + 'kind' => 'standard', + 'days_until_expiration' => 365, + 'expire_at' => '2016/02/06 12:41:52 -0600' + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('enterprise/settings/license') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show()); + } + + protected function getApiClass() + { + return 'Github\Api\Enterprise\License'; + } +} diff --git a/test/Github/Tests/Api/Enterprise/StatsTest.php b/test/Github/Tests/Api/Enterprise/StatsTest.php new file mode 100644 index 00000000000..9c4a02f9ff4 --- /dev/null +++ b/test/Github/Tests/Api/Enterprise/StatsTest.php @@ -0,0 +1,49 @@ +getJson(); + $expectedArray = json_encode($expectedJson); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('enterprise/stats/all') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('all')); + } + + protected function getJson() + { + return '{"repos":{"total_repos": 212, "root_repos": 194, "fork_repos": 18, "org_repos": 51, + "total_pushes": 3082, "total_wikis": 15 }, "hooks": { "total_hooks": 27, "active_hooks": 23, + "inactive_hooks": 4 }, "pages": { "total_pages": 36 }, "orgs": { "total_orgs": 33, "disabled_orgs": 0, + "total_teams": 60, "total_team_members": 314 }, "users": { "total_users": 254, "admin_users": 45, + "suspended_users": 21 }, "pulls": { "total_pulls": 86, "merged_pulls": 60, "mergeable_pulls": 21, + "unmergeable_pulls": 3 }, "issues": { "total_issues": 179, "open_issues": 83, "closed_issues": 96 }, + "milestones": { "total_milestones": 7, "open_milestones": 6, "closed_milestones": 1 }, "gists": + { "total_gists": 178, "private_gists": 151, "public_gists": 25 }, "comments": { "total_commit_comments": 6, + "total_gist_comments": 28, "total_issue_comments": 366, "total_pull_request_comments": 30 } }'; + } + + protected function getApiClass() + { + return 'Github\Api\Enterprise\Stats'; + } +} From daad20d4cda8b4f2d32899839b0200eeb3684d78 Mon Sep 17 00:00:00 2001 From: guillermo-fisher Date: Fri, 31 Oct 2014 10:01:49 -0400 Subject: [PATCH 05/11] Removed the unneeded docblocks. --- lib/Github/Api/Enterprise/ManagementConsole.php | 6 ------ test/Github/Tests/Api/Enterprise/LicenseTest.php | 6 ------ test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php | 6 ------ test/Github/Tests/Api/Enterprise/StatsTest.php | 6 ------ test/Github/Tests/Api/EnterpriseTest.php | 6 ------ 5 files changed, 30 deletions(-) diff --git a/lib/Github/Api/Enterprise/ManagementConsole.php b/lib/Github/Api/Enterprise/ManagementConsole.php index 2c61ccddeee..7c68d2459c8 100644 --- a/lib/Github/Api/Enterprise/ManagementConsole.php +++ b/lib/Github/Api/Enterprise/ManagementConsole.php @@ -1,10 +1,4 @@ Date: Fri, 31 Oct 2014 11:10:03 -0400 Subject: [PATCH 06/11] Sending the hash as a parameter for now. Not ideal, but will refactor at a future date. --- lib/Github/Api/Enterprise/ManagementConsole.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/Github/Api/Enterprise/ManagementConsole.php b/lib/Github/Api/Enterprise/ManagementConsole.php index 7c68d2459c8..98406dd2d11 100644 --- a/lib/Github/Api/Enterprise/ManagementConsole.php +++ b/lib/Github/Api/Enterprise/ManagementConsole.php @@ -54,11 +54,6 @@ public function keys($hash) return $this->get('/setup/api/settings/authorized-keys', $hash); } - public function getClient() - { - return $this->client; - } - /** * Sends an authenticated GET request. * @@ -69,6 +64,6 @@ public function getClient() */ protected function get($uri, $hash) { - return parent::get($uri, array('auth' => array('license', rawurlencode($hash)))); + return parent::get($uri, array('license_md5' => rawurlencode($hash))); } } From 5529dea149c46fb43a5eb6d4bab9e1bdb54c20e2 Mon Sep 17 00:00:00 2001 From: guillermo-fisher Date: Fri, 31 Oct 2014 11:22:58 -0400 Subject: [PATCH 07/11] Fixed docblock; no longer overriding "get" -- added "getWithLicenseHash". --- lib/Github/Api/Enterprise/ManagementConsole.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/Github/Api/Enterprise/ManagementConsole.php b/lib/Github/Api/Enterprise/ManagementConsole.php index 98406dd2d11..5b7f2bf3149 100644 --- a/lib/Github/Api/Enterprise/ManagementConsole.php +++ b/lib/Github/Api/Enterprise/ManagementConsole.php @@ -15,7 +15,7 @@ class ManagementConsole extends AbstractApi */ public function configcheck($hash) { - return $this->get('/setup/api/configcheck', $hash); + return $this->getWithLicenseHash('/setup/api/configcheck', $hash); } /** @@ -27,7 +27,7 @@ public function configcheck($hash) */ public function settings($hash) { - return $this->get('/setup/api/settings', $hash); + return $this->getWithLicenseHash('/setup/api/settings', $hash); } /** @@ -39,7 +39,7 @@ public function settings($hash) */ public function maintenance($hash) { - return $this->get('/setup/api/maintenance', $hash); + return $this->getWithLicenseHash('/setup/api/maintenance', $hash); } /** @@ -51,18 +51,17 @@ public function maintenance($hash) */ public function keys($hash) { - return $this->get('/setup/api/settings/authorized-keys', $hash); + return $this->getWithLicenseHash('/setup/api/settings/authorized-keys', $hash); } /** * Sends an authenticated GET request. * - * @see \Github\Api\AbstractApi::get() - * @param string $uri - * @param array $hash + * @param string $uri the request URI + * @param string $hash md5 hash of your license * @return \Guzzle\Http\EntityBodyInterface|mixed|string */ - protected function get($uri, $hash) + protected function getWithLicenseHash($uri, $hash) { return parent::get($uri, array('license_md5' => rawurlencode($hash))); } From 5b361942cf076ebe27a51a5d9885b78410f81e9f Mon Sep 17 00:00:00 2001 From: guillermo-fisher Date: Fri, 31 Oct 2014 11:31:38 -0400 Subject: [PATCH 08/11] Should be decoding and not encoding the JSON. --- lib/Github/Api/Enterprise/ManagementConsole.php | 2 +- .../Github/Tests/Api/Enterprise/ManagementConsoleTest.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/Enterprise/ManagementConsole.php b/lib/Github/Api/Enterprise/ManagementConsole.php index 5b7f2bf3149..59315b45478 100644 --- a/lib/Github/Api/Enterprise/ManagementConsole.php +++ b/lib/Github/Api/Enterprise/ManagementConsole.php @@ -63,6 +63,6 @@ public function keys($hash) */ protected function getWithLicenseHash($uri, $hash) { - return parent::get($uri, array('license_md5' => rawurlencode($hash))); + return $this->get($uri, array('license_md5' => rawurlencode($hash))); } } diff --git a/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php b/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php index cfd9b228147..ed2972c103d 100644 --- a/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php +++ b/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php @@ -15,7 +15,7 @@ public function shouldShowConfigData() { "status": "DONE", "key": "GitHub utilities" }, { "status": "DONE", "key": "GitHub applications" }, { "status": "CONFIGURING", "key": "GitHub services" }, { "status": "PENDING", "key": "Reloading appliance services" } ] }'; - $expectedArray = json_encode($expectedJson); + $expectedArray = json_decode($expectedJson); $api = $this->getApiMock(); $api->expects($this->once()) @@ -53,7 +53,7 @@ public function shouldShowSettingsData() "file", "bucket": null, "host_name": null, "key_id": null, "access_key": null }, "pages": { "enabled": true }, "collectd": { "enabled": false, "server": "", "port": "", "encryption": "", "username": "foo", "password": "bar" } }, "run_list": [ "role[configure]" ] }'; - $expectedArray = json_encode($expectedJson); + $expectedArray = json_decode($expectedJson); $api = $this->getApiMock(); $api->expects($this->once()) @@ -72,7 +72,7 @@ public function shouldShowMaintenanceStatus() $expectedJson = '{ "status": "scheduled", "scheduled_time": "Tuesday, January 22 at 15 => 34 -0800", "connection_services": [ { "name": "git operations", "number": 0 }, { "name": "mysql queries", "number": 233 }, { "name": "resque jobs", "number": 54 } ] }'; - $expectedArray = json_encode($expectedJson); + $expectedArray = json_decode($expectedJson); $api = $this->getApiMock(); $api->expects($this->once()) @@ -92,7 +92,7 @@ public function shouldShowAuthorizedKeys() "ssh-rsa 01:14:0f:f2:0f:e2:fe:e8:f4:72:62:af:75:f7:1a:88:3e:04:92:64" }, { "key": "ssh-rsa AAAAB3NzaC1yc2EAAAAB...", "pretty-print": "ssh-rsa 01:14:0f:f2:0f:e2:fe:e8:f4:72:62:af:75:f7:1a:88:3e:04:92:64" } ]'; - $expectedArray = json_encode($expectedJson); + $expectedArray = json_decode($expectedJson); $api = $this->getApiMock(); $api->expects($this->once()) From 9d4b5931f7d41628243ec0a673f0966842874efc Mon Sep 17 00:00:00 2001 From: guillermo-fisher Date: Fri, 31 Oct 2014 11:35:36 -0400 Subject: [PATCH 09/11] Should be decoding and not encoding the JSON in the StatsTest as well. --- test/Github/Tests/Api/Enterprise/StatsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/Api/Enterprise/StatsTest.php b/test/Github/Tests/Api/Enterprise/StatsTest.php index 5bb7d223fd6..1a3e3acf0d2 100644 --- a/test/Github/Tests/Api/Enterprise/StatsTest.php +++ b/test/Github/Tests/Api/Enterprise/StatsTest.php @@ -12,7 +12,7 @@ class StatsTest extends TestCase public function shouldShowStats() { $expectedJson = $this->getJson(); - $expectedArray = json_encode($expectedJson); + $expectedArray = json_decode($expectedJson); $api = $this->getApiMock(); $api->expects($this->once()) From cc01bcedec888101df7389dd0ed6adc34b6e4249 Mon Sep 17 00:00:00 2001 From: guillermo-fisher Date: Fri, 31 Oct 2014 12:08:04 -0400 Subject: [PATCH 10/11] Added second param to json_decode calls; checking that the license hash is sent with the request. --- .../Api/Enterprise/ManagementConsoleTest.php | 17 ++++++++--------- test/Github/Tests/Api/Enterprise/StatsTest.php | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php b/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php index ed2972c103d..60755693f82 100644 --- a/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php +++ b/test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php @@ -15,12 +15,12 @@ public function shouldShowConfigData() { "status": "DONE", "key": "GitHub utilities" }, { "status": "DONE", "key": "GitHub applications" }, { "status": "CONFIGURING", "key": "GitHub services" }, { "status": "PENDING", "key": "Reloading appliance services" } ] }'; - $expectedArray = json_decode($expectedJson); + $expectedArray = json_decode($expectedJson, true); $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/setup/api/configcheck') + ->with('/setup/api/configcheck', array('license_md5' => $this->getLicenseHash())) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->configcheck($this->getLicenseHash())); @@ -53,12 +53,12 @@ public function shouldShowSettingsData() "file", "bucket": null, "host_name": null, "key_id": null, "access_key": null }, "pages": { "enabled": true }, "collectd": { "enabled": false, "server": "", "port": "", "encryption": "", "username": "foo", "password": "bar" } }, "run_list": [ "role[configure]" ] }'; - $expectedArray = json_decode($expectedJson); + $expectedArray = json_decode($expectedJson, true); $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/setup/api/settings') + ->with('/setup/api/settings', array('license_md5' => $this->getLicenseHash())) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->settings($this->getLicenseHash())); @@ -72,12 +72,12 @@ public function shouldShowMaintenanceStatus() $expectedJson = '{ "status": "scheduled", "scheduled_time": "Tuesday, January 22 at 15 => 34 -0800", "connection_services": [ { "name": "git operations", "number": 0 }, { "name": "mysql queries", "number": 233 }, { "name": "resque jobs", "number": 54 } ] }'; - $expectedArray = json_decode($expectedJson); + $expectedArray = json_decode($expectedJson, true); $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/setup/api/maintenance') + ->with('/setup/api/maintenance', array('license_md5' => $this->getLicenseHash())) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->maintenance($this->getLicenseHash())); @@ -92,14 +92,13 @@ public function shouldShowAuthorizedKeys() "ssh-rsa 01:14:0f:f2:0f:e2:fe:e8:f4:72:62:af:75:f7:1a:88:3e:04:92:64" }, { "key": "ssh-rsa AAAAB3NzaC1yc2EAAAAB...", "pretty-print": "ssh-rsa 01:14:0f:f2:0f:e2:fe:e8:f4:72:62:af:75:f7:1a:88:3e:04:92:64" } ]'; - $expectedArray = json_decode($expectedJson); + $expectedArray = json_decode($expectedJson, true); $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/setup/api/settings/authorized-keys') + ->with('/setup/api/settings/authorized-keys', array('license_md5' => $this->getLicenseHash())) ->will($this->returnValue($expectedArray)); - $this->assertEquals($expectedArray, $api->keys($this->getLicenseHash())); } diff --git a/test/Github/Tests/Api/Enterprise/StatsTest.php b/test/Github/Tests/Api/Enterprise/StatsTest.php index 1a3e3acf0d2..5ee76194625 100644 --- a/test/Github/Tests/Api/Enterprise/StatsTest.php +++ b/test/Github/Tests/Api/Enterprise/StatsTest.php @@ -12,7 +12,7 @@ class StatsTest extends TestCase public function shouldShowStats() { $expectedJson = $this->getJson(); - $expectedArray = json_decode($expectedJson); + $expectedArray = json_decode($expectedJson, true); $api = $this->getApiMock(); $api->expects($this->once()) From 31ca1163c0ee86d6b76aefa56d7aa7ac8d913177 Mon Sep 17 00:00:00 2001 From: guillermo-fisher Date: Fri, 31 Oct 2014 12:30:41 -0400 Subject: [PATCH 11/11] Added remaining Stats tests. --- .../Github/Tests/Api/Enterprise/StatsTest.php | 54 +++++++++++++++++-- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/test/Github/Tests/Api/Enterprise/StatsTest.php b/test/Github/Tests/Api/Enterprise/StatsTest.php index 5ee76194625..97e28962556 100644 --- a/test/Github/Tests/Api/Enterprise/StatsTest.php +++ b/test/Github/Tests/Api/Enterprise/StatsTest.php @@ -11,8 +11,7 @@ class StatsTest extends TestCase */ public function shouldShowStats() { - $expectedJson = $this->getJson(); - $expectedArray = json_decode($expectedJson, true); + $expectedArray = $this->getStatsData(); $api = $this->getApiMock(); $api->expects($this->once()) @@ -23,9 +22,50 @@ public function shouldShowStats() $this->assertEquals($expectedArray, $api->show('all')); } - protected function getJson() + /** + * @test + * @dataProvider getTypes + */ + public function shouldShowStatsByType($type) + { + $expectedArray = $this->getStatsData($type); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with(sprintf('enterprise/stats/%s', $type)) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, call_user_func(array($api, $type))); + } + + /** + * @return array + */ + public function getTypes() + { + return array( + array('issues'), + array('hooks'), + array('milestones'), + array('orgs'), + array('comments'), + array('pages'), + array('users'), + array('gists'), + array('pulls'), + array('repos'), + array('all') + ); + } + + /** + * @param string $key + * @return mixed + */ + protected function getStatsData($key = '') { - return '{"repos":{"total_repos": 212, "root_repos": 194, "fork_repos": 18, "org_repos": 51, + $json = '{"repos":{"total_repos": 212, "root_repos": 194, "fork_repos": 18, "org_repos": 51, "total_pushes": 3082, "total_wikis": 15 }, "hooks": { "total_hooks": 27, "active_hooks": 23, "inactive_hooks": 4 }, "pages": { "total_pages": 36 }, "orgs": { "total_orgs": 33, "disabled_orgs": 0, "total_teams": 60, "total_team_members": 314 }, "users": { "total_users": 254, "admin_users": 45, @@ -34,6 +74,12 @@ protected function getJson() "milestones": { "total_milestones": 7, "open_milestones": 6, "closed_milestones": 1 }, "gists": { "total_gists": 178, "private_gists": 151, "public_gists": 25 }, "comments": { "total_commit_comments": 6, "total_gist_comments": 28, "total_issue_comments": 366, "total_pull_request_comments": 30 } }'; + $stats = json_decode($json, true); + if (is_null($key)) { + return $stats; + } elseif (array_key_exists($key, $stats)) { + return $stats[$key]; + } } protected function getApiClass()