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