Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix instance resource retrieving wrong URI

  • Loading branch information...
commit 2e24838d107b460bf17986042766ddebb8cc58ef 1 parent 4cf63c2
Kevin Burke authored
Showing with 38 additions and 3 deletions.
  1. +2 −1  Services/Twilio/Resource.php
  2. +36 −2 tests/TwilioTest.php
View
3  Services/Twilio/Resource.php
@@ -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);
}
View
38 tests/TwilioTest.php
@@ -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()
Please sign in to comment.
Something went wrong with that request. Please try again.