From 35736c239de08d0e15cbde2008413666e720eeff Mon Sep 17 00:00:00 2001 From: Thomas Stachl Date: Fri, 9 May 2014 11:50:37 -0700 Subject: [PATCH] made it work with php53 and hopefully with php52 but travis will know --- .travis.yml | 2 +- lib/Desk/Resource.php | 24 +++++++++++++++++------- tests/Desk/ClientTest.php | 18 ++++++++++++------ tests/Desk/ResourceTest.php | 14 ++++++++------ tests/DeskTest/Adapter.php | 4 ++-- 5 files changed, 40 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index 891691f..e53e3a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,11 +3,11 @@ php: - 5.5 - 5.4 - 5.3 + - 5.2 matrix: allow_failures: - php: 5.5 - - php: 5.3 before_script: - wget http://pecl.php.net/get/yaml-1.1.1.tgz diff --git a/lib/Desk/Resource.php b/lib/Desk/Resource.php index 60f7ed0..3931d23 100644 --- a/lib/Desk/Resource.php +++ b/lib/Desk/Resource.php @@ -187,7 +187,7 @@ public function delete() */ public function search($params) { - if (is_string($params)) { $params = ['q' => $params]; } + if (is_string($params)) { $params = array('q' => $params); } $uri = Zend_Uri::factory($this->_client->getEndpoint() . $this->_cleanBaseUrl() . '/search'); $uri->setQuery($params); @@ -244,7 +244,8 @@ public function byUrl($url) */ public function getHref() { - return $this->_links->getSelf()['href']; + $self = $this->_links->getSelf(); + return $self['href']; } /** @@ -266,7 +267,8 @@ public function setHref($url) */ public function getResourceType() { - return $this->_links->getSelf()['class']; + $self = $this->_links->getSelf(); + return $self['class']; } /** @@ -279,7 +281,10 @@ public function getPage() if (!array_key_exists('page', $this->queryParams())) { $this->_execute(); } - return $this->queryParams()['page']; + + $query = $this->queryParams(); + + return $query['page']; } /** @@ -304,7 +309,10 @@ public function getPerPage() if (!array_key_exists('per_page', $this->queryParams())) { $this->_execute(); } - return $this->queryParams()['per_page']; + + $query = $this->queryParams(); + + return $query['per_page']; } /** @@ -453,7 +461,8 @@ protected function _setupData($data = array(), $loaded = true) { $this->_links = new Varien_Object(self::arrayRemove($data, '_links')); $this->_embedded = new Varien_Object(self::arrayRemove($data, '_embedded')); - $this->_data = (new Varien_Object($data))->setOrigData(); + $this->_data = new Varien_Object($data); + $this->_data->setOrigData(); $this->_loaded = $loaded; return $this; } @@ -466,7 +475,8 @@ protected function _setupData($data = array(), $loaded = true) private function _cleanBaseUrl() { $pattern = array('/\/search$/', '/\/\d+$/'); - return preg_replace($pattern, '', explode('?', $this->getHref())[0]); + $explode = explode('?', $this->getHref()); + return preg_replace($pattern, '', $explode[0]); } /** diff --git a/tests/Desk/ClientTest.php b/tests/Desk/ClientTest.php index 369b452..f8f5219 100644 --- a/tests/Desk/ClientTest.php +++ b/tests/Desk/ClientTest.php @@ -47,19 +47,22 @@ public function testOptionsAllowsZendConfig() public function testGet() { $response = $this->getClient()->get('/api/v2/cases/3014'); - $this->assertEquals('Testing Quick Case', Zend_Json::decode($response->getBody())['subject']); + $body = Zend_Json::decode($response->getBody()); + $this->assertEquals('Testing Quick Case', $body['subject']); } public function testPost() { $response = $this->getClient()->post('/api/v2/topics', array('name' => 'Test Topic')); - $this->assertEquals('Test Topic', Zend_Json::decode($response->getBody())['name']); + $body = Zend_Json::decode($response->getBody()); + $this->assertEquals('Test Topic', $body['name']); } public function testPatch() { $response = $this->getClient()->patch('/api/v2/topics/655433', array('name' => 'Test Updated Topic')); - $this->assertEquals('Test Updated Topic', Zend_Json::decode($response->getBody())['name']); + $body = Zend_Json::decode($response->getBody()); + $this->assertEquals('Test Updated Topic', $body['name']); } public function testDelete() @@ -77,19 +80,22 @@ public function testHead() public function testOauthGet() { $response = $this->getClient('oauth')->get('/api/v2/cases/3014'); - $this->assertEquals('Testing Quick Case', Zend_Json::decode($response->getBody())['subject']); + $body = Zend_Json::decode($response->getBody()); + $this->assertEquals('Testing Quick Case', $body['subject']); } public function testOauthPost() { $response = $this->getClient('oauth')->post('/api/v2/topics', array('name' => 'Test Topic')); - $this->assertEquals('Test Topic', Zend_Json::decode($response->getBody())['name']); + $body = Zend_Json::decode($response->getBody()); + $this->assertEquals('Test Topic', $body['name']); } public function testOauthPatch() { $response = $this->getClient('oauth')->patch('/api/v2/topics/655435', array('name' => 'Test Updated Topic')); - $this->assertEquals('Test Updated Topic', Zend_Json::decode($response->getBody())['name']); + $body = Zend_Json::decode($response->getBody()); + $this->assertEquals('Test Updated Topic', $body['name']); } public function testOauthDelete() diff --git a/tests/Desk/ResourceTest.php b/tests/Desk/ResourceTest.php index 5b2ae2e..5506b25 100644 --- a/tests/Desk/ResourceTest.php +++ b/tests/Desk/ResourceTest.php @@ -7,7 +7,8 @@ class Desk_ResourceTest extends DeskTest_TestCase { public function testBuildSelfLink() { - $this->assertEquals('/momo', Desk_Resource::buildSelfLink('/momo')['_links']['self']['href']); + $links = Desk_Resource::buildSelfLink('/momo'); + $this->assertEquals('/momo', $links['_links']['self']['href']); } public function testArrayRemove() @@ -172,14 +173,15 @@ public function testExecuteThrowsError() public function testFilterUpdateAction() { - $customer = $this->getClient()->getCustomers()->getEntries()[0]; + $entries = $this->getClient()->getCustomers()->getEntries(); + $customer = $entries[0]; $count = count($customer->getPhoneNumbers()); - $number = ['type' => 'home', 'value' => '(415) 555-1234']; + $number = array('type' => 'home', 'value' => '(415) 555-1234'); - $customer->update([ - 'phone_numbers' => [$number], + $customer->update(array( + 'phone_numbers' => array($number), 'phone_numbers_update_action' => 'append' - ]); + )); $new_count = count($customer->reload()->getPhoneNumbers()); diff --git a/tests/DeskTest/Adapter.php b/tests/DeskTest/Adapter.php index aaf6641..7504c10 100644 --- a/tests/DeskTest/Adapter.php +++ b/tests/DeskTest/Adapter.php @@ -101,10 +101,10 @@ public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $bo $file = $this->getFixtureFilename(); if (!file_exists(dirname($file))) { mkdir(dirname($file), 0777, true); } - yaml_emit_file($file, [ + yaml_emit_file($file, array( 'request' => preg_replace('/^Authorization:.*\r?\n/m', '', $request), 'response' => $this->_response - ]); + )); return $request; }