Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix instance resource retrieving wrong URI
  • Loading branch information
Kevin Burke committed Jul 3, 2012
1 parent 4cf63c2 commit 2e24838
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Services/Twilio/Resource.php
Expand Up @@ -17,11 +17,12 @@ public function __construct($client, $uri, $params = array())
{
$this->subresources = array();
$this->client = $client;
$this->uri = $uri;

foreach ($params as $name => $param) {
$this->$name = $param;
}

$this->uri = $uri;
$this->init($client, $uri);
}

Expand Down
38 changes: 36 additions & 2 deletions tests/TwilioTest.php
Expand Up @@ -132,16 +132,50 @@ function testListResource() {
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array(
'total' => 1,
'calls' => array(array('status' => 'Completed', 'sid' => 'CA123'))
'calls' => array(array('status' => 'completed', 'sid' => 'CA123'))
))
));
$client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
$page = $client->account->calls->getPage(0, 10);
$call = current($page->getItems());
$this->assertEquals('Completed', $call->status);
$this->assertEquals('completed', $call->status);
$this->assertEquals(1, $page->total);
}

function testInstanceResourceUriConstructedProperly() {
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('get')->once()
->with('/2010-04-01/Accounts/AC123/Calls.json?Page=0&PageSize=10')
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array(
'total' => 1,
'calls' => array(array(
'status' => 'in-progress',
'sid' => 'CA123',
'uri' => 'junk_uri'
))
))
));
$http->shouldReceive('get')->once()
->with('/2010-04-01/Accounts/AC123/Calls/CA123.json')
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array(
'status' => 'completed'
))
));
$client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
$page = $client->account->calls->getPage(0, 10);
$call = current($page->getItems());

/* trigger api fetch by trying to retrieve nonexistent var */
try {
$call->nonexistent;
} catch (Exception $e) {
// pass
}
$this->assertSame($call->status, 'completed');
}

function testIterateOverPage() {
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('get')->once()
Expand Down

0 comments on commit 2e24838

Please sign in to comment.