Skip to content
This repository has been archived by the owner on Jun 23, 2020. It is now read-only.

Commit

Permalink
made it work with php53 and hopefully with php52 but travis will know
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Stachl committed May 9, 2014
1 parent 312a4c8 commit 35736c2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 17 additions & 7 deletions lib/Desk/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -244,7 +244,8 @@ public function byUrl($url)
*/
public function getHref()
{
return $this->_links->getSelf()['href'];
$self = $this->_links->getSelf();
return $self['href'];
}

/**
Expand All @@ -266,7 +267,8 @@ public function setHref($url)
*/
public function getResourceType()
{
return $this->_links->getSelf()['class'];
$self = $this->_links->getSelf();
return $self['class'];
}

/**
Expand All @@ -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'];
}

/**
Expand All @@ -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'];
}

/**
Expand Down Expand Up @@ -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;
}
Expand All @@ -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]);
}

/**
Expand Down
18 changes: 12 additions & 6 deletions tests/Desk/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
14 changes: 8 additions & 6 deletions tests/Desk/ResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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());

Expand Down
4 changes: 2 additions & 2 deletions tests/DeskTest/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 35736c2

Please sign in to comment.