[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 use \Mockery as m; 4 5 class IncomingPhoneNumbersTest extends PHPUnit_Framework_TestCase { 6 7 protected $apiResponse = array( 8 'incoming_phone_numbers' => array( 9 array( 10 'sid' => 'PN123', 11 'sms_fallback_method' => 'POST', 12 'voice_method' => 'POST', 13 'friendly_name' => '(510) 564-7903', 14 ) 15 ), 16 ); 17 18 function testGetNumberWithResult() { 19 $http = m::mock(new Services_Twilio_TinyHttp); 20 $http->shouldReceive('get')->once() 21 ->with('/2010-04-01/Accounts/AC123/IncomingPhoneNumbers.json?Page=0&PageSize=1&PhoneNumber=%2B14105551234') 22 ->andReturn(array(200, array('Content-Type' => 'application/json'), 23 json_encode($this->apiResponse) 24 ) 25 ); 26 $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); 27 $number = $client->account->incoming_phone_numbers->getNumber('+14105551234'); 28 $this->assertEquals('PN123', $number->sid); 29 } 30 31 function testGetNumberNoResults() { 32 $http = m::mock(new Services_Twilio_TinyHttp); 33 $http->shouldReceive('get')->once() 34 ->with('/2010-04-01/Accounts/AC123/IncomingPhoneNumbers.json?Page=0&PageSize=1&PhoneNumber=%2B14105551234') 35 ->andReturn(array(200, array('Content-Type' => 'application/json'), 36 json_encode(array( 37 'incoming_phone_numbers' => array(), 38 'page' => 0, 39 'page_size' => 1, 40 )) 41 ) 42 ); 43 $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); 44 $number = $client->account->incoming_phone_numbers->getNumber('+14105551234'); 45 $this->assertNull($number); 46 } 47 48 function testGetMobile() { 49 $http = m::mock(new Services_Twilio_TinyHttp); 50 $http->shouldReceive('get')->once() 51 ->with('/2010-04-01/Accounts/AC123/IncomingPhoneNumbers/Mobile.json?Page=0&PageSize=50') 52 ->andReturn(array(200, array('Content-Type' => 'application/json'), 53 json_encode($this->apiResponse) 54 )); 55 $http->shouldReceive('get')->once() 56 ->with('/2010-04-01/Accounts/AC123/IncomingPhoneNumbers/Mobile.json?Page=1&PageSize=50') 57 ->andReturn(array(400, array('Content-Type' => 'application/json'), 58 '{"status":400,"message":"foo", "code": "20006"}' 59 )); 60 $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); 61 foreach ($client->account->incoming_phone_numbers->mobile as $num) { 62 $this->assertEquals('(510) 564-7903', $num->friendly_name); 63 } 64 } 65 66 function testGetLocal() { 67 $http = m::mock(new Services_Twilio_TinyHttp); 68 $http->shouldReceive('get')->once() 69 ->with('/2010-04-01/Accounts/AC123/IncomingPhoneNumbers/Local.json?Page=0&PageSize=50') 70 ->andReturn(array(200, array('Content-Type' => 'application/json'), 71 json_encode($this->apiResponse) 72 )); 73 $http->shouldReceive('get')->once() 74 ->with('/2010-04-01/Accounts/AC123/IncomingPhoneNumbers/Local.json?Page=1&PageSize=50') 75 ->andReturn(array(400, array('Content-Type' => 'application/json'), 76 '{"status":400,"message":"foo", "code": "20006"}' 77 )); 78 $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); 79 80 foreach ($client->account->incoming_phone_numbers->local as $num) { 81 $this->assertEquals('(510) 564-7903', $num->friendly_name); 82 } 83 } 84 85 function testGetTollFree() { 86 $http = m::mock(new Services_Twilio_TinyHttp); 87 $http->shouldReceive('get')->once() 88 ->with('/2010-04-01/Accounts/AC123/IncomingPhoneNumbers/TollFree.json?Page=0&PageSize=50') 89 ->andReturn(array(200, array('Content-Type' => 'application/json'), 90 json_encode($this->apiResponse) 91 )); 92 $http->shouldReceive('get')->once() 93 ->with('/2010-04-01/Accounts/AC123/IncomingPhoneNumbers/TollFree.json?Page=1&PageSize=50') 94 ->andReturn(array(400, array('Content-Type' => 'application/json'), 95 '{"status":400,"message":"foo", "code": "20006"}' 96 )); 97 $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); 98 foreach ($client->account->incoming_phone_numbers->toll_free as $num) { 99 $this->assertEquals('(510) 564-7903', $num->friendly_name); 100 } 101 } 102 103 } 104
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |