forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMembersTest.php
83 lines (72 loc) · 3.41 KB
/
MembersTest.php
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
<?php
use \Mockery as m;
class MembersTest extends PHPUnit_Framework_TestCase {
protected $formHeaders = array('Content-Type' => 'application/x-www-form-urlencoded');
function testFront() {
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('get')->once()
->with('/2010-04-01/Accounts/AC123/Queues/QQ123/Members/Front.json')
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('call_sid' => 'CA123', 'position' => 0))
));
$client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
$queue = $client->account->queues->get('QQ123');
$firstMember = $queue->members->front();
$this->assertSame($firstMember->call_sid, 'CA123');
}
function testDequeueFront() {
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('post')->once()
->with('/2010-04-01/Accounts/AC123/Queues/QQ123/Members/Front.json',
$this->formHeaders, 'Url=http%3A%2F%2Ffoo.com&Method=POST')
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('call_sid' => 'CA123', 'position' => 0))
));
$client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
$queue = $client->account->queues->get('QQ123');
$firstMember = $queue->members->front();
$firstMember->dequeue('http://foo.com');
}
function testDequeueSid() {
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('post')->once()
->with('/2010-04-01/Accounts/AC123/Queues/QQ123/Members/CA123.json',
$this->formHeaders, 'Url=http%3A%2F%2Ffoo.com&Method=GET')
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('call_sid' => 'CA123', 'position' => 0))
));
$client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
$queue = $client->account->queues->get('QQ123');
$firstMember = $queue->members->get('CA123');
$firstMember->dequeue('http://foo.com', 'GET');
}
function testMemberIterate() {
$http = m::mock(new Services_Twilio_TinyHttp);
$resp = json_encode(
array(
'queue_members' => array(
array('call_sid' => 'CA123', 'wait_time' => 30)
),
'end' => 1,
)
);
$http->shouldReceive('get')->once()
->with('/2010-04-01/Accounts/AC123/Queues/QQ123/Members.json?Page=0&PageSize=50')
->andReturn(array(200, array('Content-Type' => 'application/json'), $resp
));
$http->shouldReceive('get')->once()
->with('/2010-04-01/Accounts/AC123/Queues/QQ123/Members.json?Page=1&PageSize=50')
->andReturn(array(400, array('Content-Type' => 'application/json'),
'{"status":400,"message":"foo", "code": "20006"}'
));
$client = new Services_Twilio('AC123', '123', '2010-04-01', $http);
$queue = $client->account->queues->get('QQ123');
foreach($queue->members as $member) {
$this->assertSame($member->call_sid, 'CA123');
$this->assertSame($member->wait_time, 30);
}
}
function tearDown() {
m::close();
}
}