[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 use \Mockery as m; 4 5 class UsageRecordsTest extends PHPUnit_Framework_TestCase { 6 7 function testGetBaseRecord() { 8 9 $http = m::mock(new Services_Twilio_TinyHttp); 10 $http->shouldReceive('get')->once() 11 ->with('/2010-04-01/Accounts/AC123/Usage/Records.json?Page=0&PageSize=50') 12 ->andReturn(array(200, array('Content-Type' => 'application/json'), 13 json_encode(array('usage_records' => array( 14 array( 15 'category' => 'sms', 16 'count' => 5, 17 'end_date' => '2012-08-01', 18 ), 19 array( 20 'category' => 'calleridlookups', 21 'count' => 5, 22 'end_date' => '2012-08-01', 23 )) 24 )) 25 )); 26 $http->shouldReceive('get')->once() 27 ->with('/2010-04-01/Accounts/AC123/Usage/Records.json?Page=1&PageSize=50') 28 ->andReturn(array(400, array('Content-Type' => 'application/json'), 29 '{"status":400,"message":"foo", "code": "20006"}' 30 )); 31 32 $client = new Services_Twilio('AC123', '456bef', '2010-04-01', $http); 33 foreach ($client->account->usage_records as $record) { 34 $this->assertSame(5, $record->count); 35 } 36 } 37 38 function testUsageRecordSubresource() { 39 40 $http = m::mock(new Services_Twilio_TinyHttp); 41 $http->shouldReceive('get')->once() 42 ->with('/2010-04-01/Accounts/AC123/Usage/Records/LastMonth.json?Page=0&PageSize=50') 43 ->andReturn(array(200, array('Content-Type' => 'application/json'), 44 json_encode(array('usage_records' => array( 45 array( 46 'category' => 'sms', 47 'count' => 4, 48 'end_date' => '2012-08-01', 49 ), 50 array( 51 'category' => 'calleridlookups', 52 'count' => 4, 53 'end_date' => '2012-08-01', 54 )) 55 )) 56 )); 57 $http->shouldReceive('get')->once() 58 ->with('/2010-04-01/Accounts/AC123/Usage/Records/LastMonth.json?Page=1&PageSize=50') 59 ->andReturn(array(400, array('Content-Type' => 'application/json'), 60 '{"status":400,"message":"foo", "code": "20006"}' 61 )); 62 63 $client = new Services_Twilio('AC123', '456bef', '2010-04-01', $http); 64 foreach ($client->account->usage_records->last_month as $record) { 65 $this->assertSame('2012-08-01', $record->end_date); 66 } 67 } 68 69 function testGetCategory() { 70 $http = m::mock(new Services_Twilio_TinyHttp); 71 $http->shouldReceive('get')->once() 72 ->with('/2010-04-01/Accounts/AC123/Usage/Records.json?Page=0&PageSize=1&Category=calls') 73 ->andReturn(array(200, array('Content-Type' => 'application/json'), 74 json_encode(array('usage_records' => array( 75 array( 76 'category' => 'calls', 77 'count' => 4, 78 'price' => '100.30', 79 'end_date' => '2012-08-01', 80 )), 81 )) 82 )); 83 $client = new Services_Twilio('AC123', '456bef', '2010-04-01', $http); 84 $callRecord = $client->account->usage_records->getCategory('calls'); 85 $this->assertSame('100.30', $callRecord->price); 86 } 87 88 function testFilterUsageRecords() { 89 $http = m::mock(new Services_Twilio_TinyHttp); 90 $params = 'Page=0&PageSize=50&StartDate=2012-08-01&EndDate=2012-08-31'; 91 $http->shouldReceive('get')->once() 92 ->with('/2010-04-01/Accounts/AC123/Usage/Records.json?' . $params) 93 ->andReturn(array(200, array('Content-Type' => 'application/json'), 94 json_encode(array('usage_records' => array( 95 array( 96 'category' => 'sms', 97 'count' => 4, 98 'price' => '300.30', 99 ), 100 array( 101 'category' => 'calls', 102 'count' => 4, 103 'price' => '100.30', 104 )), 105 )) 106 )); 107 $params = 'Page=1&PageSize=50&StartDate=2012-08-01&EndDate=2012-08-31'; 108 $http->shouldReceive('get')->once() 109 ->with('/2010-04-01/Accounts/AC123/Usage/Records.json?' . $params) 110 ->andReturn(array(400, array('Content-Type' => 'application/json'), 111 '{"status":400,"message":"foo", "code": "20006"}' 112 )); 113 $client = new Services_Twilio('AC123', '456bef', '2010-04-01', $http); 114 foreach ($client->account->usage_records->getIterator(0, 50, array( 115 'StartDate' => '2012-08-01', 116 'EndDate' => '2012-08-31', 117 )) as $record) { 118 $this->assertSame(4, $record->count); 119 } 120 } 121 122 function testGetCategoryOnSubresource() { 123 $http = m::mock(new Services_Twilio_TinyHttp); 124 $params = 'Page=0&PageSize=1&Category=sms'; 125 $http->shouldReceive('get')->once() 126 ->with('/2010-04-01/Accounts/AC123/Usage/Records/Today.json?' . $params) 127 ->andReturn(array(200, array('Content-Type' => 'application/json'), 128 json_encode(array('usage_records' => array( 129 array( 130 'category' => 'sms', 131 'count' => 4, 132 'price' => '100.30', 133 'end_date' => '2012-08-30' 134 )), 135 )) 136 )); 137 $client = new Services_Twilio('AC123', '456bef', '2010-04-01', $http); 138 $smsRecord = $client->account->usage_records->today->getCategory('sms'); 139 $this->assertSame($smsRecord->end_date, '2012-08-30'); 140 } 141 142 function testTimeSeriesFilters() { 143 $http = m::mock(new Services_Twilio_TinyHttp); 144 $params = 'Page=0&PageSize=50&StartDate=2012-08-01&EndDate=2012-08-31&Category=recordings'; 145 $http->shouldReceive('get')->once() 146 ->with('/2010-04-01/Accounts/AC123/Usage/Records/Daily.json?' . $params) 147 ->andReturn(array(200, array('Content-Type' => 'application/json'), 148 json_encode(array('usage_records' => array( 149 array( 150 'category' => 'recordings', 151 'count' => 4, 152 'price' => '100.30', 153 'end_date' => '2012-08-31' 154 ), 155 array( 156 'category' => 'recordings', 157 'count' => 4, 158 'price' => '100.30', 159 'end_date' => '2012-08-30' 160 )), 161 )) 162 )); 163 $params = 'Page=1&PageSize=50&StartDate=2012-08-01&EndDate=2012-08-31&Category=recordings'; 164 $http->shouldReceive('get')->once() 165 ->with('/2010-04-01/Accounts/AC123/Usage/Records/Daily.json?' . $params) 166 ->andReturn(array(400, array('Content-Type' => 'application/json'), 167 '{"status":400,"message":"foo", "code": "20006"}' 168 )); 169 $client = new Services_Twilio('AC123', '456bef', '2010-04-01', $http); 170 foreach ($client->account->usage_records->daily->getIterator(0, 50, array( 171 'StartDate' => '2012-08-01', 172 'EndDate' => '2012-08-31', 173 'Category' => 'recordings', 174 )) as $record) { 175 $this->assertSame($record->category, 'recordings'); 176 $this->assertSame($record->price, '100.30'); 177 } 178 } 179 } 180
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 |