Skip to content

Commit

Permalink
Merge pull request #56 from elwinmartin/master
Browse files Browse the repository at this point in the history
Updated formatting to pass cs lint
  • Loading branch information
rossgrambo-zz authored Jul 20, 2020
2 parents 780e897 + bb70835 commit 2144e36
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 32 deletions.
18 changes: 8 additions & 10 deletions src/Asana/Dispatcher/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ public function __construct()
{
// All of Asana's IDs are int64. If the current build of PHP does not
// support integers that large, we specify that integers that are too
// large should be represented as strings instead. Otherwise PHP would
// large should be represented as strings instead. Otherwise PHP would
// convert them to floats.
// Note that Httpful's JsonHandler does not support that option which
// Note that Httpful's JsonHandler does not support that option which
// is why we have to register our own JSON handler.
if (PHP_INT_SIZE < 8) {
\Httpful\Httpful::register(
\Httpful\Mime::JSON,
\Httpful\Mime::JSON,
new \Asana\Dispatcher\Handlers\JsonHandler(array('parse_options' => JSON_BIGINT_AS_STRING))
);
}
Expand All @@ -38,8 +38,8 @@ public function request($method, $uri, $requestOptions)
->expectsJson();

if (isset($requestOptions['curl'])) {
foreach($requestOptions['curl'] as $curlopt => $curlval){
$request->addOnCurlOption($curlopt,$curlval);
foreach ($requestOptions['curl'] as $curlopt => $curlval) {
$request->addOnCurlOption($curlopt, $curlval);
}
}

Expand All @@ -61,16 +61,14 @@ public function request($method, $uri, $requestOptions)

// If the user's PHP version supports curl_file_create, use it.
if (function_exists('curl_file_create')) {
if ( (isset($file[1]) && $file[1] != null) ) {
if ((isset($file[1]) && $file[1] != null)) {
$mimetype = '';
if ( (isset($file[2]) && $file[2] != null) ) {
if ((isset($file[2]) && $file[2] != null)) {
$mimetype = $file[2];
}
$body[$name] = curl_file_create($tmpFilePath, $mimetype, $file[1]);
}
}
// Otherwise we can still use the '@' notation.
else {
} else { // Otherwise we can still use the '@' notation.
$body[$name] = '@' . $tmpFilePath;
if (isset($file[1]) && $file[1] != null) {
$body[$name] .= ';filename=' . $file[1];
Expand Down
8 changes: 5 additions & 3 deletions src/Asana/Dispatcher/Handlers/JsonHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ public function init(array $args)
public function parse($body)
{
$body = $this->stripBom($body);
if (empty($body))
if (empty($body)) {
return null;
}
$parsed = json_decode($body, $this->decode_as_array, $this->depth, $this->parse_options);
if (is_null($parsed) && 'null' !== strtolower($body))
if (is_null($parsed) && 'null' !== strtolower($body)) {
throw new \Exception("Unable to parse response as JSON");
}
return $parsed;
}

Expand All @@ -46,4 +48,4 @@ public function serialize($payload)
{
return json_encode($payload);
}
}
}
2 changes: 1 addition & 1 deletion src/Asana/Dispatcher/OAuthDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ protected function authenticate($request)
}
return $request->addHeader("Authorization", "Bearer " . $this->accessToken);
}
}
}
31 changes: 26 additions & 5 deletions tests/Asana/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,12 @@ public function testRateLimiting()
array(429, array('Retry-After' => '0.1' ), '{}'),
array(200, null, '{ "data": "me" }')
);
$this->dispatcher->registerResponse('/users/me', function () use (&$res) { return array_shift($res); });
$this->dispatcher->registerResponse(
'/users/me',
function () use (&$res) {
return array_shift($res);
}
);

$result = $this->client->users->me();
$this->assertEquals($result, 'me');
Expand All @@ -229,7 +234,12 @@ public function testRateLimitedTwice()
array(429, array('Retry-After' => '0.1' ), '{}'),
array(200, null, '{ "data": "me" }')
);
$this->dispatcher->registerResponse('/users/me', function () use (&$res) { return array_shift($res); });
$this->dispatcher->registerResponse(
'/users/me',
function () use (&$res) {
return array_shift($res);
}
);

$result = $this->client->users->me();
$this->assertEquals($result, 'me');
Expand All @@ -244,7 +254,12 @@ public function testServerErrorRetry()
array(500, null, '{}'),
array(200, null, '{ "data": "me" }')
);
$this->dispatcher->registerResponse('/users/me', function () use (&$res) { return array_shift($res); });
$this->dispatcher->registerResponse(
'/users/me',
function () use (&$res) {
return array_shift($res);
}
);

$result = $this->client->users->me(null, array('max_retries' => 1));
$this->assertEquals(count($this->dispatcher->calls), 2);
Expand All @@ -260,7 +275,12 @@ public function testServerErrorRetryBackoff()
array(500, null, '{}'),
array(200, null, '{ "data": "me" }')
);
$this->dispatcher->registerResponse('/users/me', function () use (&$res) { return array_shift($res); });
$this->dispatcher->registerResponse(
'/users/me',
function () use (&$res) {
return array_shift($res);
}
);

$result = $this->client->users->me();
$this->assertEquals(count($this->dispatcher->calls), 4);
Expand All @@ -269,7 +289,8 @@ public function testServerErrorRetryBackoff()

public function testGetNamedParameters()
{
$this->dispatcher->registerResponse('/tasks?limit=50&workspace=14916&assignee=me', 200, null, '{ "data": "foo" }');
$res = '{ "data": "foo" }';
$this->dispatcher->registerResponse('/tasks?limit=50&workspace=14916&assignee=me', 200, null, $res);

$options = array('iterator_type' => false);
$result = $this->client->tasks->findAll(array('workspace' => 14916, 'assignee' => 'me'), $options);
Expand Down
23 changes: 15 additions & 8 deletions tests/Asana/OAuthDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@
use Asana\Dispatcher\OAuthDispatcher;

// Extend dispatcher to expose protected methods for testing.
class FakeOauthDispatcher extends OAuthDispatcher {
public function authenticate($request) {
return parent::authenticate($request);
}
};
class FakeOauthDispatcher extends OAuthDispatcher
{
public function authenticate($request)
{
return parent::authenticate($request);
}
}

class OAuthDispatcherTest extends \PHPUnit\Framework\TestCase
{
protected function setUp(): void
{
$this->dispatcher = new FakeOAuthDispatcher(array(
'client_id' => 'fake_client_id'));
$this->dispatcher = new FakeOAuthDispatcher(
array(
'client_id' => 'fake_client_id'
)
);
}

public function testAuthenticateNoToken()
Expand All @@ -37,6 +42,8 @@ public function testAuthenticateUsesToken()
$request = new MockRequest($this->dispatcher);
$this->dispatcher->authenticate($request);
$this->assertEquals(
$request->headers, array('Authorization' => 'Bearer fake_token'));
$request->headers,
array('Authorization' => 'Bearer fake_token')
);
}
}
6 changes: 3 additions & 3 deletions tests/Asana/Resources/AttachmentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public function testAttachmentsCreateOnTask()

// If the user's PHP version supports curl_file_create, use it.
if (function_exists('curl_file_create')) {
$this->assertInstanceOf('CURLFile',$fileDescription);
$this->assertEquals('file name',$fileDescription->getPostFilename());
$this->assertEquals('file content-type',$fileDescription->getMimeType());
$this->assertInstanceOf('CURLFile', $fileDescription);
$this->assertEquals('file name', $fileDescription->getPostFilename());
$this->assertEquals('file content-type', $fileDescription->getMimeType());
} else {
$this->assertStringMatchesFormat('%Sfilename=file name%S', $fileDescription);
$this->assertStringMatchesFormat('%Stype=file content-type%S', $fileDescription);
Expand Down
5 changes: 3 additions & 2 deletions tests/Asana/Resources/WebhooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ public function testWebhooksCreate()

public function testWebhooksGetAll()
{
$this->dispatcher->registerResponse('/webhooks?limit=50&workspace=1337', 200, null, '{ "data": [' . json_encode($this->data) . '] }');
$res = '{ "data": [' . json_encode($this->data) . '] }';
$this->dispatcher->registerResponse('/webhooks?limit=50&workspace=1337', 200, null, $res);

$result = $this->client->webhooks->getAll(array("workspace" => 1337));
foreach ($result as $res) {
$this->verifyWebhookData($res);
$this->verifyWebhookData($res);
}
}

Expand Down

0 comments on commit 2144e36

Please sign in to comment.