[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 use \Mockery as m; 4 5 class UsageTriggersTest extends PHPUnit_Framework_TestCase { 6 function testRetrieveTrigger() { 7 $http = m::mock(new Services_Twilio_TinyHttp); 8 $http->shouldReceive('get')->once() 9 ->with('/2010-04-01/Accounts/AC123/Usage/Triggers/UT123.json') 10 ->andReturn(array(200, array('Content-Type' => 'application/json'), 11 json_encode(array( 12 'sid' => 'UT123', 13 'date_created' => 'Tue, 09 Oct 2012 19:27:24 +0000', 14 'recurring' => null, 15 'usage_category' => 'totalprice', 16 )) 17 )); 18 $client = new Services_Twilio('AC123', '456bef', '2010-04-01', $http); 19 $usageSid = 'UT123'; 20 $usageTrigger = $client->account->usage_triggers->get($usageSid); 21 $this->assertSame('totalprice', $usageTrigger->usage_category); 22 } 23 24 protected $formHeaders = array('Content-Type' => 'application/x-www-form-urlencoded'); 25 26 function testUpdateTrigger() { 27 $http = m::mock(new Services_Twilio_TinyHttp); 28 $usageSid = 'UT123'; 29 $http->shouldReceive('post')->once() 30 ->with('/2010-04-01/Accounts/AC123/Usage/Triggers/UT123.json', 31 $this->formHeaders, 'FriendlyName=new') 32 ->andReturn(array(200, array('Content-Type' => 'application/json'), 33 json_encode(array( 34 'friendly_name' => 'new', 35 'sid' => 'UT123', 36 'uri' => '/2010-04-01/Accounts/AC123/Usage/Triggers/UT123.json' 37 )) 38 )); 39 $http->shouldReceive('get')->once() 40 ->with('/2010-04-01/Accounts/AC123/Usage/Triggers/UT123.json') 41 ->andReturn(array(200, array('Content-Type' => 'application/json'), 42 json_encode(array( 43 'sid' => 'UT123', 44 'friendly_name' => 'new', 45 )) 46 )); 47 $client = new Services_Twilio('AC123', '456bef', '2010-04-01', $http); 48 $usageTrigger = $client->account->usage_triggers->get($usageSid); 49 $usageTrigger->update(array( 50 'FriendlyName' => 'new', 51 )); 52 $usageTrigger2 = $client->account->usage_triggers->get($usageSid); 53 $this->assertSame('new', $usageTrigger2->friendly_name); 54 } 55 56 function testFilterTriggerList() { 57 $http = m::mock(new Services_Twilio_TinyHttp); 58 $params = 'Page=0&PageSize=50&UsageCategory=sms'; 59 $http->shouldReceive('get')->once() 60 ->with('/2010-04-01/Accounts/AC123/Usage/Triggers.json?' . $params) 61 ->andReturn(array(200, array('Content-Type' => 'application/json'), 62 json_encode(array('usage_triggers' => array( 63 array( 64 'usage_category' => 'sms', 65 'current_value' => '4', 66 'trigger_value' => '100.30', 67 ), 68 array( 69 'usage_category' => 'sms', 70 'current_value' => '4', 71 'trigger_value' => '400.30', 72 )), 73 'next_page_uri' => '/2010-04-01/Accounts/AC123/Usage/Triggers.json?UsageCategory=sms&Page=1&PageSize=50', 74 )) 75 )); 76 $params = 'UsageCategory=sms&Page=1&PageSize=50'; 77 $http->shouldReceive('get')->once() 78 ->with('/2010-04-01/Accounts/AC123/Usage/Triggers.json?' . $params) 79 ->andReturn(array(400, array('Content-Type' => 'application/json'), 80 '{"status":400,"message":"foo", "code": "20006"}' 81 )); 82 $client = new Services_Twilio('AC123', '456bef', '2010-04-01', $http); 83 foreach ($client->account->usage_triggers->getIterator( 84 0, 50, array( 85 'UsageCategory' => 'sms', 86 )) as $trigger 87 ) { 88 $this->assertSame($trigger->current_value, "4"); 89 } 90 } 91 92 function testCreateTrigger() { 93 $http = m::mock(new Services_Twilio_TinyHttp); 94 $params = 'UsageCategory=sms&TriggerValue=100&CallbackUrl=foo'; 95 $http->shouldReceive('post')->once() 96 ->with('/2010-04-01/Accounts/AC123/Usage/Triggers.json', 97 $this->formHeaders, $params) 98 ->andReturn(array(201, array('Content-Type' => 'application/json'), 99 json_encode(array( 100 'usage_category' => 'sms', 101 'sid' => 'UT123', 102 'uri' => '/2010-04-01/Accounts/AC123/Usage/Triggers/UT123.json' 103 )) 104 )); 105 $client = new Services_Twilio('AC123', '456bef', '2010-04-01', $http); 106 $trigger = $client->account->usage_triggers->create( 107 'sms', 108 '100', 109 'foo' 110 ); 111 $this->assertSame('sms', $trigger->usage_category); 112 } 113 } 114
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 |