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
|
<?php
use \Mockery as m;
class MessagesTest extends PHPUnit_Framework_TestCase { protected $formHeaders = array('Content-Type' => 'application/x-www-form-urlencoded');
function testCreateMessage() { $http = m::mock(new Services_Twilio_TinyHttp); $http->shouldReceive('post')->once() ->with('/2010-04-01/Accounts/AC123/Messages.json', $this->formHeaders, 'From=%2B1222&To=%2B44123&Body=Hi+there') ->andReturn(array(200, array('Content-Type' => 'application/json'), json_encode(array('sid' => 'SM123')) )); $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); $msg = $client->account->messages->sendMessage('+1222', '+44123', 'Hi there'); $this->assertSame('SM123', $msg->sid); }
function testCreateMessageWithMedia() { $http = m::mock(new Services_Twilio_TinyHttp); $http->shouldReceive('post')->once() ->with('/2010-04-01/Accounts/AC123/Messages.json', $this->formHeaders, 'From=%2B1222&To=%2B44123&MediaUrl=http%3A%2F%2Fexample.com%2Fimage1') ->andReturn(array(200, array('Content-Type' => 'application/json'), json_encode(array('sid' => 'SM123')) )); $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); $msg = $client->account->messages->sendMessage('+1222', '+44123', null, array('http://example.com/image1')); $this->assertSame('SM123', $msg->sid); }
function testCreateMessageWithMediaAndBody() { $http = m::mock(new Services_Twilio_TinyHttp); $http->shouldReceive('post')->once() ->with('/2010-04-01/Accounts/AC123/Messages.json', $this->formHeaders, 'From=%2B1222&To=%2B44123&MediaUrl=http%3A%2F%2Fexample.com%2Fimage1&Body=Hi+there') ->andReturn(array(200, array('Content-Type' => 'application/json'), json_encode(array('sid' => 'SM123')) )); $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); $msg = $client->account->messages->sendMessage('+1222', '+44123', 'Hi there', array('http://example.com/image1') ); $this->assertSame('SM123', $msg->sid); }
function testCreateMessageWithMultipleMedia() { $http = m::mock(new Services_Twilio_TinyHttp); $http->shouldReceive('post')->once() ->with('/2010-04-01/Accounts/AC123/Messages.json', $this->formHeaders, 'From=%2B1222&To=%2B44123&MediaUrl=http%3A%2F%2Fexample.com%2Fimage1&MediaUrl=http%3A%2F%2Fexample.com%2Fimage2') ->andReturn(array(200, array('Content-Type' => 'application/json'), json_encode(array('sid' => 'SM123')) )); $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); $msg = $client->account->messages->sendMessage('+1222', '+44123', null, array('http://example.com/image1', 'http://example.com/image2')); $this->assertSame('SM123', $msg->sid); }
function testBadMessageThrowsException() { $this->setExpectedException('Services_Twilio_RestException'); $http = m::mock(new Services_Twilio_TinyHttp); $http->shouldReceive('post')->once() ->with('/2010-04-01/Accounts/AC123/Messages.json', $this->formHeaders, 'From=%2B1222&To=%2B44123&Body=' . str_repeat('hi', 801)) ->andReturn(array(400, array('Content-Type' => 'application/json'), json_encode(array( 'status' => '400', 'message' => 'Too long', )) )); $client = new Services_Twilio('AC123', '123', null, $http); $msg = $client->account->messages->sendMessage('+1222', '+44123', str_repeat('hi', 801)); }
function testRawCreate() { $http = m::mock(new Services_Twilio_TinyHttp); $http->shouldReceive('post')->once() ->with('/2010-04-01/Accounts/AC123/Messages.json', $this->formHeaders, 'From=%2B1222&To=%2B44123&MediaUrl=http%3A%2F%2Fexample.com%2Fimage1&MediaUrl=http%3A%2F%2Fexample.com%2Fimage2') ->andReturn(array(200, array('Content-Type' => 'application/json'), json_encode(array('sid' => 'SM123')) )); $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); $msg = $client->account->messages->create(array( 'From' => '+1222', 'To' => '+44123', 'MediaUrl' => array('http://example.com/image1', 'http://example.com/image2') )); $this->assertSame('SM123', $msg->sid); }
function testDeleteMessage() { $http = m::mock(new Services_Twilio_TinyHttp); $http->shouldReceive('delete')->once() ->with('/2010-04-01/Accounts/AC123/Messages/ME123.json') ->andReturn(array(204, array('Content-Type' => 'application/json'), '' )); $client = new Services_Twilio('AC123', '123', null, $http); $client->account->messages->delete('ME123'); }
function testNewline() { $http = m::mock(new Services_Twilio_TinyHttp); $http->shouldReceive('post')->once() ->with('/2010-04-01/Accounts/AC123/Messages.json', $this->formHeaders, 'Body=Hello%0A%0AHello') ->andReturn(array(200, array('Content-Type' => 'application/json'), json_encode(array('sid' => 'SM123')) )); $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); $msg = $client->account->messages->create(array( 'Body' => "Hello\n\nHello" )); $this->assertSame('SM123', $msg->sid); } }
|