Skip to content

Commit

Permalink
Merge branch 'master' of github.com:zendesk/zendesk_api_client_php
Browse files Browse the repository at this point in the history
  • Loading branch information
kcasas committed Dec 5, 2016
2 parents 86220d9 + 2813612 commit 1692370
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/Zendesk/API/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ public static function send(
}

try {
list ($request, $requestOptions) = $client->getAuth()->prepareRequest($request, $requestOptions);
// enable anonymous access
if ($client->getAuth()) {
list ($request, $requestOptions) = $client->getAuth()->prepareRequest($request, $requestOptions);
}
$response = $client->guzzle->send($request, $requestOptions);
} catch (RequestException $e) {
$requestException = RequestException::create($e->getRequest(), $e->getResponse());
Expand Down
8 changes: 4 additions & 4 deletions src/Zendesk/API/Resources/Core/Locales.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function setUpRoutes()
*/
public function findAllPublic(array $params = [])
{
$this->findAll($params, __FUNCTION__);
return $this->findAll($params, __FUNCTION__);
}

/**
Expand All @@ -52,7 +52,7 @@ public function findAllPublic(array $params = [])
*/
public function findAllAgent(array $params = [])
{
$this->findAll($params, __FUNCTION__);
return $this->findAll($params, __FUNCTION__);
}

/**
Expand All @@ -67,7 +67,7 @@ public function findAllAgent(array $params = [])
*/
public function findCurrent(array $params = [])
{
$this->findAll($params, __FUNCTION__);
return $this->findAll($params, __FUNCTION__);
}

/**
Expand All @@ -81,6 +81,6 @@ public function findCurrent(array $params = [])
*/
public function findBest(array $params = [])
{
$this->findAll($params, __FUNCTION__);
return $this->findAll($params, __FUNCTION__);
}
}
4 changes: 3 additions & 1 deletion src/Zendesk/API/Resources/Core/OAuthClients.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ protected function setUpRoutes()
* Find all oauth clients belonging to the logged in user.
*
* @param array $params
*
* @return \stdClass | null
*/
public function findAllMine(array $params = [])
{
$this->findAll($params, __FUNCTION__);
return $this->findAll($params, __FUNCTION__);
}
}
31 changes: 31 additions & 0 deletions tests/Zendesk/API/UnitTests/Core/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace Zendesk\API\UnitTests\Core;

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Zendesk\API\Http;
use Zendesk\API\HttpClient;
use Zendesk\API\UnitTests\BasicTest;
use Zendesk\API\Utilities\Auth;

Expand All @@ -11,6 +15,33 @@
*/
class AuthTest extends BasicTest
{
/**
* Test if request is still sent even without authentication
*/
public function testAnonymousAccess()
{
// mock client
$client = $this
->getMockBuilder(HttpClient::class)
->disableOriginalConstructor()
->getMock();
$client->method('getHeaders')->willReturn([]);
$client->expects(self::once())->method('getAuth')->willReturn(null);

// prepareRequest should not be called
$auth = $this
->getMockBuilder(Auth::class)
->disableOriginalConstructor()
->getMock();
$auth->expects(self::never())->method('prepareRequest');
$client->expects(self::once())->method('getAuth')->willReturn($auth);

// send request
$client->guzzle = $this->getMockBuilder(Client::class)->getMock();
$client->guzzle->method('send')->willReturn(new Response);
Http::send($client, '');
}

/**
* Test the preparing of a request for basic authentication.
*/
Expand Down

0 comments on commit 1692370

Please sign in to comment.