Skip to content

Commit

Permalink
Merge pull request #105 from Asana/jv-asana-remove-sample-and-tests-o…
Browse files Browse the repository at this point in the history
…f-non-autogen-methods

Use autogenerated methods for tests
  • Loading branch information
jv-asana authored Nov 30, 2022
2 parents c3a0f4f + ee84233 commit 60713e3
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 60 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ $project = $client->projects->createProjectForWorkspace($workspaceGid, array('na
echo "Created project with gid: " . $project->gid;
```

Methods that return multiple items (e.x. `findAll`) return an items iterator by default. See the "Collections" section
Methods that return multiple items (e.x. `getTasks`, `getProjects`, `getPortfolios`, etc.) return an items iterator by default. See the "Collections" section

## Options

Expand All @@ -130,7 +130,7 @@ Asana\Client::$DEFAULTS['page_size'] = 1000;
$client->options['page_size'] = 1000;

// per-request:
$client->tasks->findAll(array('project' => 1234), array('page_size' => 1000));
$client->tasks->getTasks(array('project' => 1234), array('page_size' => 1000));
```

### Available options
Expand Down
4 changes: 2 additions & 2 deletions examples/example-accesstoken.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
// create a $client->with a Personal Access Token
$client = Asana\Client::accessToken($ASANA_ACCESS_TOKEN);

$me = $client->users->me();
echo "me="; var_dump($client->users->me());
$me = $client->users->getUser('me');
echo "me="; var_dump($client->users->getUser('me'));
6 changes: 3 additions & 3 deletions examples/example-create-project-and-stream-events.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

// create a $client->with a Personal Access Token
$client = Asana\Client::accessToken($ASANA_ACCESS_TOKEN);
$me = $client->users->me();
echo "me="; var_dump($client->users->me());
$me = $client->users->getUser('me');
echo "me="; var_dump($client->users->getUser('me'));

// find your "Personal Projects" project
$personalProjectsArray = array_filter($me->workspaces, function($item) { return $item->name === 'Personal Projects'; });
$personalProjects = array_pop($personalProjectsArray);
var_dump($personalProjects);
$projects = $client->projects->findByWorkspace($personalProjects->id, null, array('iterator_type' => false, 'page_size' => null))->data;
$projects = $client->projects->getProjectsForWorkspace($personalProjects->id, null, array('iterator_type' => false, 'page_size' => null))->data;
echo "personal projects="; var_dump($projects);

// create a "demo project" if it doesn't exist
Expand Down
6 changes: 3 additions & 3 deletions examples/example-create-task-and-upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

// create a $client->with a Personal Access Token
$client = Asana\Client::accessToken($ASANA_ACCESS_TOKEN);
$me = $client->users->me();
echo "me="; var_dump($client->users->me());
$me = $client->users->getUser('me');
echo "me="; var_dump($client->users->getUser('me'));

// find your "Personal Projects" workspace
$personalProjectsArray = array_filter($me->workspaces, function($item) { return $item->name === 'Personal Projects'; });
$personalProjects = array_pop($personalProjectsArray);
var_dump($personalProjects);
$projects = $client->projects->findByWorkspace($personalProjects->gid, null, array('iterator_type' => false, 'page_size' => null))->data;
$projects = $client->projects->getProjectsForWorkspace($personalProjects->gid, null, array('iterator_type' => false, 'page_size' => null))->data;
echo "personal projects="; var_dump($projects);

// create a "demo project" if it doesn't exist
Expand Down
6 changes: 3 additions & 3 deletions examples/example-oauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
exit(1);
}

echo "Hello " . $client->users->me()->name . "\n";
echo "Hello " . $client->users->getUser('me')->name . "\n";
echo "Your access token is: " . json_encode($token) . "\n";
echo "Exchanging your refresh token for a new access token because access tokens expire\n";

Expand All @@ -61,7 +61,7 @@

echo "Your new access token is: " . json_encode($token) . "\n";
echo "You are a member of the following workspaces:\n";
$workspaces = $client->workspaces->findAll();
$workspaces = $client->workspaces->getWorkspaces();
foreach ($workspaces as $workspace) {
echo $workspace->name . "\n";
}
Expand All @@ -76,4 +76,4 @@
'token' => json_decode($token)
));

echo "Your registered email address is: " . $client->users->me()->email;
echo "Your registered email address is: " . $client->users->getUser('me')->email;
2 changes: 1 addition & 1 deletion examples/example-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function client($token=null)
try {
if ('/' == $_SERVER['SCRIPT_NAME']) {
if (isset($_SESSION['token'])) {
$me = client($_SESSION['token'])->users->me();
$me = client($_SESSION['token'])->users->getUser('me');
echo '<p>Hello ' . $me->name . '</p><p><a href="/logout">Logout</a></p>';
} else {
$state = null;
Expand Down
52 changes: 26 additions & 26 deletions tests/Asana/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function testClientGet()
{
$this->dispatcher->registerResponse('/users/me', 200, null, '{ "data": "foo" }');

$result = $this->client->users->me();
$result = $this->client->users->getUser('me');
$this->assertEquals($result, 'foo');
}

Expand All @@ -25,7 +25,7 @@ public function testNotAuthorized()

$this->dispatcher->registerResponse('/users/me', 401, null, '{ "errors": [{ "message": "Not Authorized" }]}');

$this->client->users->me();
$this->client->users->getUser('me');
}

public function testInvalidRequest()
Expand All @@ -34,7 +34,7 @@ public function testInvalidRequest()

$this->dispatcher->registerResponse('/tasks?limit=50', 400, null, '{ "errors": [{ "message": "Missing input" }] }');

$this->client->tasks->findAll(null, array('iterator_type' => false));
$this->client->tasks->getTasks(null, array('iterator_type' => false));
}

public function testServerError()
Expand All @@ -44,7 +44,7 @@ public function testServerError()
$res = '{ "errors": [ { "message": "Server Error", "phrase": "6 sad squid snuggle softly" } ] }';
$this->dispatcher->registerResponse('/users/me', 500, null, $res);

$this->client->users->me();
$this->client->users->getUser('me');
}

public function testNotFound()
Expand All @@ -54,7 +54,7 @@ public function testNotFound()
$res = '{ "errors": [ { "message": "user: Unknown object: 1234" } ] }';
$this->dispatcher->registerResponse('/users/1234', 404, null, $res);

$this->client->users->findById(1234);
$this->client->users->getUser(1234);
}

public function testForbidden()
Expand All @@ -64,21 +64,21 @@ public function testForbidden()
$res = '{ "errors": [ { "message": "user: Forbidden" } ] }';
$this->dispatcher->registerResponse('/users/1234', 403, null, $res);

$this->client->users->findById(1234);
$this->client->users->getUser(1234);
}

public function testOptionPretty()
{
$this->dispatcher->registerResponse('/users/me?opt_pretty=true', 200, null, '{ "data": "foo" }');

$this->assertEquals($this->client->users->me(null, array('pretty' => true)), 'foo');
$this->assertEquals($this->client->users->getUser('me', null, array('pretty' => true)), 'foo');
}

public function testOptionFields()
{
$this->dispatcher->registerResponse('/tasks/1224?opt_fields=name%2Cnotes', 200, null, '{ "data": "foo" }');

$result = $this->client->tasks->findById(1224, null, array("fields" => array('name','notes')));
$result = $this->client->tasks->getTask(1224, null, array("fields" => array('name','notes')));
$this->assertEquals($result, 'foo');
}

Expand All @@ -87,7 +87,7 @@ public function testOptionExpand()
$req = '{ "data": { "assignee": 1234 }, "options": { "expand" : ["projects"] } }';
$this->dispatcher->registerResponse('/tasks/1001', 200, null, '{ "data": "foo" }');

$result = $this->client->tasks->update(1001, array('assignee' => 1234), array('expand' => array('projects')));
$result = $this->client->tasks->updateTask(1001, array('assignee' => 1234), array('expand' => array('projects')));
$this->assertEquals($result, 'foo');
$this->assertEquals(json_decode($this->dispatcher->calls[0]['request']->payload), json_decode($req));
}
Expand All @@ -107,7 +107,7 @@ public function testPagination()
$this->dispatcher->registerResponse('/projects/1337/tasks?limit=5&offset=ABCDEF', 200, null, $res);

$options = array( 'limit' => 5, 'offset' => 'ABCDEF', 'iterator_type' => false );
$result = $this->client->tasks->findByProject(1337, null, $options);
$result = $this->client->tasks->getTasksForProject(1337, null, $options);
$this->assertEquals($result, json_decode($res));
}

Expand All @@ -120,7 +120,7 @@ public function testItemIteratorItemLimitLessThanItems()
$this->dispatcher->registerResponse('/projects/1337/tasks?limit=2', 200, null, $res);

$options = array('item_limit' => 2, 'page_size' => 2, 'iterator_type' => 'items');
$iterator = $this->client->tasks->findByProject(1337, null, $options);
$iterator = $this->client->tasks->getTasksForProject(1337, null, $options);
$iterator->rewind();
$this->assertEquals($iterator->valid(), true);
$this->assertEquals($iterator->current(), 'a');
Expand All @@ -142,7 +142,7 @@ public function testItemIteratorItemLimitEqualItems()
$this->dispatcher->registerResponse('/projects/1337/tasks?limit=1&offset=a', 200, null, $res);

$options = array('item_limit' => 3, 'page_size' => 2, 'iterator_type' => 'items');
$iterator = $this->client->tasks->findByProject(1337, null, $options);
$iterator = $this->client->tasks->getTasksForProject(1337, null, $options);
$iterator->rewind();
$this->assertEquals($iterator->valid(), true);
$this->assertEquals($iterator->current(), 'a');
Expand All @@ -167,7 +167,7 @@ public function testItemIteratorItemLimitGreaterThanItems()
$this->dispatcher->registerResponse('/projects/1337/tasks?limit=2&offset=a', 200, null, $res);

$options = array('item_limit' => 4, 'page_size' => 2, 'iterator_type' => 'items');
$iterator = $this->client->tasks->findByProject(1337, null, $options);
$iterator = $this->client->tasks->getTasksForProject(1337, null, $options);
$iterator->rewind();
$this->assertEquals($iterator->valid(), true);
$this->assertEquals($iterator->current(), 'a');
Expand All @@ -192,7 +192,7 @@ public function testItemIteratorPreserveOptFields()
$this->dispatcher->registerResponse('/projects/1337/tasks?limit=1&offset=a&opt_fields=foo', 200, null, $res);

$options = array('fields' => array('foo'), 'item_limit' => 3, 'page_size' => 2, 'iterator_type' => 'items');
$iterator = $this->client->tasks->findByProject(1337, null, $options);
$iterator = $this->client->tasks->getTasksForProject(1337, null, $options);
$iterator->rewind();
$this->assertEquals($iterator->valid(), true);
$this->assertEquals($iterator->current(), 'a');
Expand Down Expand Up @@ -220,7 +220,7 @@ function () use (&$res) {
}
);

$result = $this->client->users->me();
$result = $this->client->users->getUser('me');
$this->assertEquals($result, 'me');
$this->assertEquals(count($this->dispatcher->calls), 2);
$this->assertEquals($sleepCalls, array(0.1));
Expand All @@ -241,7 +241,7 @@ function () use (&$res) {
}
);

$result = $this->client->users->me();
$result = $this->client->users->getUser('me');
$this->assertEquals($result, 'me');
$this->assertEquals(count($this->dispatcher->calls), 3);
$this->assertEquals($sleepCalls, array(0.1, 0.1));
Expand All @@ -261,7 +261,7 @@ function () use (&$res) {
}
);

$result = $this->client->users->me(null, array('max_retries' => 1));
$result = $this->client->users->getUser('me', null, array('max_retries' => 1));
$this->assertEquals(count($this->dispatcher->calls), 2);
$this->assertEquals($sleepCalls, array(1.0));
}
Expand All @@ -282,7 +282,7 @@ function () use (&$res) {
}
);

$result = $this->client->users->me();
$result = $this->client->users->getUser('me');
$this->assertEquals(count($this->dispatcher->calls), 4);
$this->assertEquals($sleepCalls, array(1.0, 2.0, 4.0));
}
Expand All @@ -293,7 +293,7 @@ public function testGetNamedParameters()
$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);
$result = $this->client->tasks->getTasks(array('workspace' => 14916, 'assignee' => 'me'), $options);
$this->assertEquals($result, json_decode('{ "data": "foo" }'));
}

Expand All @@ -308,7 +308,7 @@ public function testPostNamedParameters()
}';
$this->dispatcher->registerResponse('/tasks', 201, null, '{ "data": "foo" }');

$result = $this->client->tasks->create(
$result = $this->client->tasks->createTask(
array('assignee' => 1235, 'followers' => array(5678), 'name' => "Hello, world.")
);
$this->assertEquals($result, 'foo');
Expand All @@ -326,7 +326,7 @@ public function testPutNamedParameters()
}';
$this->dispatcher->registerResponse('/tasks/1001', 200, null, '{ "data": "foo" }');

$result = $this->client->tasks->update(
$result = $this->client->tasks->updateTask(
1001,
array('assignee' => 1235, 'followers' => array(5678), 'name' => "Hello, world.")
);
Expand All @@ -344,7 +344,7 @@ public function testAsanaChangeHeaderNone()
null,
'{ "data": "foo" }');

$this->client->tasks->update(
$this->client->tasks->updateTask(
1001,
array('assignee' => 1235, 'followers' => array(5678), 'name' => "Hello, world.")
);
Expand All @@ -362,7 +362,7 @@ public function testAsanaChangeHeaderEnable()
array('asana-change' => 'name=string_ids;info=something;affected=true'),
'{ "data": "foo" }');

$this->client->tasks->update(
$this->client->tasks->updateTask(
1001,
array('assignee' => 1235, 'followers' => array(5678), 'name' => "Hello, world."),
array('headers' => array('asana-enable' => 'string_ids'))
Expand All @@ -381,7 +381,7 @@ public function testAsanaChangeHeaderDisable()
array('asana-change' => 'name=string_ids;info=something;affected=true'),
'{ "data": "foo" }');

$this->client->tasks->update(
$this->client->tasks->updateTask(
1001,
array('assignee' => 1235, 'followers' => array(5678), 'name' => "Hello, world."),
array('headers' => array('asana-disable' => 'string_ids'))
Expand All @@ -400,7 +400,7 @@ public function testAsanaChangeHeaderSingle()
array('asana-change' => 'name=string_ids;info=something;affected=true'),
'{ "data": "foo" }');

$this->client->tasks->update(
$this->client->tasks->updateTask(
1001,
array('assignee' => 1235, 'followers' => array(5678), 'name' => "Hello, world.")
);
Expand All @@ -418,7 +418,7 @@ public function testAsanaChangeHeaderMultiple()
array('asana-change' => 'name=string_ids;info=something;affected=true,name=new_sections;info=something;affected=true'),
'{ "data": "foo" }');

$this->client->tasks->update(
$this->client->tasks->updateTask(
1001,
array('assignee' => 1235, 'followers' => array(5678), 'name' => "Hello, world.")
);
Expand Down
4 changes: 2 additions & 2 deletions tests/Asana/Resources/WebhooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ private function verifyWebhookData($webhook)
$this->assertEquals($webhook->active, $this->data['active']);
}

public function testWebhooksCreate()
public function testWebhooksCreateWebhook()
{
$this->dispatcher->registerResponse('/webhooks', 200, null, '{ "data": ' . json_encode($this->data) . ' }');

$result = $this->client->webhooks->create(array('resource' => 111, 'target' => 'https://foo/123'));
$result = $this->client->webhooks->createWebhook(array('resource' => 111, 'target' => 'https://foo/123'));
$this->verifyWebhookData($result);
}

Expand Down
Loading

0 comments on commit 60713e3

Please sign in to comment.