Permalink
Browse files

Merge pull request #69 from kevinburke/more-tests

More tests
  • Loading branch information...
kyleconroy committed Jun 15, 2012
2 parents 497c911 + 98c532e commit 0d2b09075808436b77525d8ca583114efafae148
Showing with 71 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +7 −0 tests/CapabilityTest.php
  3. +35 −0 tests/ResourcesTest.php
  4. +28 −0 tests/TwilioTest.php
View
@@ -7,3 +7,4 @@ vendor/*
composer.lock
composer.phar
.idea
+coverage
View
@@ -93,4 +93,11 @@ function testClientNameValidation() {
$token->allowClientIncoming('@');
}
+ function zeroLengthNameInvalid() {
+ $this->setExpectedException('InvalidArgumentException');
+ $token = new Services_Twilio_Capability('AC123', 'foo');
+ $token->allowClientIncoming("");
+ }
+
+
}
View
@@ -210,6 +210,41 @@ function tearDown()
}
}
+class SMSMessagesTest extends PHPUnit_Framework_TestCase
+{
+ protected $formHeaders = array('Content-Type' => 'application/x-www-form-urlencoded');
+
+ function testCreateMessage() {
+ $http = m::mock(new Services_Twilio_TinyHttp);
+ $http->shouldReceive('post')->once()
+ ->with('/2010-04-01/Accounts/AC123/SMS/Messages.json', $this->formHeaders,
+ 'From=%2B1222&To=%2B44123&Body=Hi+there')
+ ->andReturn(array(200, array('Content-Type' => 'application/json'),
+ json_encode(array('sid' => 'SM123'))
+ ));
+ $client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
+ $sms = $client->account->sms_messages->create('+1222', '+44123', 'Hi there');
+ $this->assertSame('SM123', $sms->sid);
+ }
+
+ function testBadMessageThrowsException() {
+ $this->setExpectedException('Services_Twilio_RestException');
+ $http = m::mock(new Services_Twilio_TinyHttp);
+ $http->shouldReceive('post')->once()
+ ->with('/2010-04-01/Accounts/AC123/SMS/Messages.json', $this->formHeaders,
+ 'From=%2B1222&To=%2B44123&Body=' . str_repeat('hi', 81))
+ ->andReturn(array(400, array('Content-Type' => 'application/json'),
+ json_encode(array(
+ 'status' => '400',
+ 'message' => 'Too long',
+ ))
+ ));
+ $client = new Services_Twilio('AC123', '123', null, $http);
+ $sms = $client->account->sms_messages->create('+1222', '+44123',
+ str_repeat('hi', 81));
+ }
+}
+
class CallsTest extends PHPUnit_Framework_TestCase
{
View
@@ -25,6 +25,17 @@ function testNeedsRefining() {
$this->assertEquals('Robert Paulson', $client->account->friendly_name);
}
+ function testNoContentTypeThrowsException() {
+ $this->setExpectedException('DomainException');
+ $http = m::mock(new Services_Twilio_TinyHttp);
+ $http->shouldReceive('get')->once()
+ ->with('/2010-04-01/Accounts/AC123.json')
+ ->andReturn(array(200, array(), json_encode(array())
+ ));
+ $client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
+ $client->account->friendly_name;
+ }
+
function testAccessSidAvoidsNetworkCall() {
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('get')->never();
@@ -125,6 +136,23 @@ function testListResource() {
$this->assertEquals(1, $page->total);
}
+ function testIterateOverPage() {
+ $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' => 'Completed', 'sid' => 'CA123'))
+ ))
+ ));
+ $client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
+ $page = $client->account->calls->getPage(0, 10);
+ foreach ($page->getIterator() as $pageitems) {
+ $this->assertSame('CA123', $pageitems->sid);
+ }
+ }
+
function testAsymmetricallyNamedResources() {
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('get')->once()

0 comments on commit 0d2b090

Please sign in to comment.