Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add JGithubMeta object to interact with Meta API endpoint #1831

Merged
merged 1 commit into from

3 participants

Michael Babker ianmacl Don Gilbert
Michael Babker
Owner

No description provided.

ianmacl

There is a unit test error. Please fix it up and ask for the request to be reopened.

ianmacl ianmacl closed this
Michael Babker
Owner

Any suggestions on how to get past that error? This method is unique in that it's not strictly returning the response object, but I have it doing post processing on the implied response. The test failure occurs because the method doesn't have the response data to process.

Don Gilbert
Collaborator
Michael Babker
Owner

No idea. Unit testing isn't one of my stronger points, but if so, I'm all for trying.

Michael Babker
Owner

OK, it was user error. :blush:

Michael Babker mbabker reopened this
Don Gilbert
Collaborator

Looks better Michael.

Don Gilbert dongilbert merged commit 6510e7d into from
Michael Babker mbabker referenced this pull request from a commit in joomla/joomla-framework
Michael Babker mbabker Port joomla/joomla-platform#1831 7d5de65
Michael Babker mbabker referenced this pull request from a commit in joomla-framework/github-api
Michael Babker mbabker Port joomla/joomla-platform#1831 813d407
Don Gilbert dongilbert referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
16 libraries/joomla/github/github.php
View
@@ -23,6 +23,7 @@
* @property-read JGithubAccount $account GitHub API object for account references.
* @property-read JGithubHooks $hooks GitHub API object for hooks.
* @property-read JGithubUsers $users GitHub API object for users.
+ * @property-read JGithubMeta $meta GitHub API object for meta.
*
* @package Joomla.Platform
* @subpackage GitHub
@@ -109,6 +110,12 @@ class JGithub
protected $users;
/**
+ * @var JGithubMeta GitHub API object for meta.
+ * @since 13.1
+ */
+ protected $meta;
+
+ /**
* Constructor.
*
* @param JRegistry $options GitHub options object.
@@ -234,6 +241,15 @@ public function __get($name)
}
return $this->users;
}
+
+ if ($name == 'meta')
+ {
+ if ($this->meta == null)
+ {
+ $this->meta = new JGithubMeta($this->options, $this->client);
+ }
+ return $this->meta;
+ }
}
/**
59 libraries/joomla/github/meta.php
View
@@ -0,0 +1,59 @@
+<?php
+/**
+ * @package Joomla.Platform
+ * @subpackage GitHub
+ *
+ * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+defined('JPATH_PLATFORM') or die;
+
+/**
+ * GitHub API Meta class.
+ *
+ * @package Joomla.Platform
+ * @subpackage GitHub
+ * @since 13.1
+ */
+class JGithubMeta extends JGithubObject
+{
+ /**
+ * Method to get the authorized IP addresses for services
+ *
+ * @return array Authorized IP addresses
+ *
+ * @since 13.1
+ * @throws DomainException
+ */
+ public function getMeta()
+ {
+ // Build the request path.
+ $path = '/meta';
+
+ $githubIps = $this->processResponse($this->client->get($this->fetchUrl($path)), 200);
+
+ /*
+ * The response body returns the IP addresses in CIDR format
+ * Decode the response body and strip the subnet mask information prior to
+ * returning the data to the user. We're assuming quite a bit here that all
+ * masks will be /32 as they are as of the time of development.
+ */
+
+ $authorizedIps = array();
+
+ foreach ($githubIps as $key => $serviceIps)
+ {
+ // The first level contains an array of IPs based on the service
+ $authorizedIps[$key] = array();
+
+ foreach ($serviceIps as $serviceIp)
+ {
+ // The second level is each individual IP address, strip the mask here
+ $authorizedIps[$key][] = substr($serviceIp, 0, -3);
+ }
+ }
+
+ return $authorizedIps;
+ }
+}
123 tests/suites/unit/joomla/github/JGithubMetaTest.php
View
@@ -0,0 +1,123 @@
+<?php
+/**
+ * @package Joomla.UnitTest
+ * @subpackage Github
+ *
+ * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+/**
+ * Test class for JGithubMeta.
+ *
+ * @package Joomla.UnitTest
+ * @subpackage Github
+ * @since 13.1
+ */
+class JGithubMetaTest extends TestCase
+{
+ /**
+ * @var JRegistry Options for the GitHub object.
+ * @since 13.1
+ */
+ protected $options;
+
+ /**
+ * @var JGithubHttp Mock client object.
+ * @since 13.1
+ */
+ protected $client;
+
+ /**
+ * @var JHttpResponse Mock response object.
+ * @since 13.1
+ */
+ protected $response;
+
+ /**
+ * @var JGithubMeta Object under test.
+ * @since 13.1
+ */
+ protected $object;
+
+ /**
+ * @var string Sample JSON string.
+ * @since 13.1
+ */
+ protected $sampleString = '{"hooks":["127.0.0.1/32","192.168.1.1/32"],"git":["127.0.0.1/32"]}';
+
+ /**
+ * @var string Sample JSON error message.
+ * @since 13.1
+ */
+ protected $errorString = '{"message": "Generic Error"}';
+
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test is executed.
+ *
+ * @return void
+ *
+ * @since 13.1
+ */
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->options = new JRegistry;
+ $this->client = $this->getMock('JGithubHttp', array('get', 'post', 'delete', 'patch', 'put'));
+ $this->response = $this->getMock('JHttpResponse');
+
+ $this->object = new JGithubMeta($this->options, $this->client);
+ }
+
+ /**
+ * Tests the getMeta method
+ *
+ * @return void
+ *
+ * @since 13.1
+ */
+ public function testGetMeta()
+ {
+ $this->response->code = 200;
+ $this->response->body = $this->sampleString;
+
+ $decodedResponse = array(
+ 'hooks' => array('127.0.0.1', '192.168.1.1'),
+ 'git' => array('127.0.0.1')
+ );
+
+ $this->client->expects($this->once())
+ ->method('get')
+ ->with('/meta')
+ ->will($this->returnValue($this->response));
+
+ $this->assertThat(
+ $this->object->getMeta(),
+ $this->equalTo($decodedResponse)
+ );
+ }
+
+ /**
+ * Tests the getMeta method - failure
+ *
+ * @return void
+ *
+ * @since 13.1
+ *
+ * @expectedException DomainException
+ */
+ public function testGetMetaFailure()
+ {
+ $this->response->code = 500;
+ $this->response->body = $this->errorString;
+
+ $this->client->expects($this->once())
+ ->method('get')
+ ->with('/meta')
+ ->will($this->returnValue($this->response));
+
+ $this->object->getMeta();
+ }
+}
24 tests/suites/unit/joomla/github/JGithubTest.php
View
@@ -1,23 +1,20 @@
<?php
/**
* @package Joomla.UnitTest
- * @subpackage Client
+ * @subpackage Github
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
-require_once JPATH_PLATFORM . '/joomla/github/github.php';
-
/**
* Test class for JGithub.
*
* @package Joomla.UnitTest
* @subpackage Github
- *
* @since 11.1
*/
-class JGithubTest extends PHPUnit_Framework_TestCase
+class JGithubTest extends TestCase
{
/**
* @var JRegistry Options for the GitHub object.
@@ -32,7 +29,7 @@ class JGithubTest extends PHPUnit_Framework_TestCase
protected $client;
/**
- * @var JGithubIssues Object under test.
+ * @var JGithub Object under test.
* @since 11.4
*/
protected $object;
@@ -218,6 +215,21 @@ public function test__GetHooks()
}
/**
+ * Tests the magic __get method - meta
+ *
+ * @since 13.1
+ *
+ * @return void
+ */
+ public function test__GetMeta()
+ {
+ $this->assertThat(
+ $this->object->meta,
+ $this->isInstanceOf('JGithubMeta')
+ );
+ }
+
+ /**
* Tests the magic __get method - failure
*
* @since 11.3
Something went wrong with that request. Please try again.