[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 use \Mockery as m; 4 5 class MessagesTest extends PHPUnit_Framework_TestCase 6 { 7 protected $formHeaders = array('Content-Type' => 'application/x-www-form-urlencoded'); 8 9 function testCreateMessage() { 10 $http = m::mock(new Services_Twilio_TinyHttp); 11 $http->shouldReceive('post')->once() 12 ->with('/2010-04-01/Accounts/AC123/Messages.json', $this->formHeaders, 13 'From=%2B1222&To=%2B44123&Body=Hi+there') 14 ->andReturn(array(200, array('Content-Type' => 'application/json'), 15 json_encode(array('sid' => 'SM123')) 16 )); 17 $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); 18 $msg = $client->account->messages->sendMessage('+1222', '+44123', 'Hi there'); 19 $this->assertSame('SM123', $msg->sid); 20 } 21 22 function testCreateMessageWithMedia() { 23 $http = m::mock(new Services_Twilio_TinyHttp); 24 $http->shouldReceive('post')->once() 25 ->with('/2010-04-01/Accounts/AC123/Messages.json', $this->formHeaders, 26 'From=%2B1222&To=%2B44123&MediaUrl=http%3A%2F%2Fexample.com%2Fimage1') 27 ->andReturn(array(200, array('Content-Type' => 'application/json'), 28 json_encode(array('sid' => 'SM123')) 29 )); 30 $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); 31 $msg = $client->account->messages->sendMessage('+1222', '+44123', null, 32 array('http://example.com/image1')); 33 $this->assertSame('SM123', $msg->sid); 34 } 35 36 function testCreateMessageWithMediaAndBody() { 37 $http = m::mock(new Services_Twilio_TinyHttp); 38 $http->shouldReceive('post')->once() 39 ->with('/2010-04-01/Accounts/AC123/Messages.json', $this->formHeaders, 40 'From=%2B1222&To=%2B44123&MediaUrl=http%3A%2F%2Fexample.com%2Fimage1&Body=Hi+there') 41 ->andReturn(array(200, array('Content-Type' => 'application/json'), 42 json_encode(array('sid' => 'SM123')) 43 )); 44 $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); 45 $msg = $client->account->messages->sendMessage('+1222', '+44123', 'Hi there', 46 array('http://example.com/image1') 47 ); 48 $this->assertSame('SM123', $msg->sid); 49 } 50 51 function testCreateMessageWithMultipleMedia() { 52 $http = m::mock(new Services_Twilio_TinyHttp); 53 $http->shouldReceive('post')->once() 54 ->with('/2010-04-01/Accounts/AC123/Messages.json', $this->formHeaders, 55 'From=%2B1222&To=%2B44123&MediaUrl=http%3A%2F%2Fexample.com%2Fimage1&MediaUrl=http%3A%2F%2Fexample.com%2Fimage2') 56 ->andReturn(array(200, array('Content-Type' => 'application/json'), 57 json_encode(array('sid' => 'SM123')) 58 )); 59 $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); 60 $msg = $client->account->messages->sendMessage('+1222', '+44123', null, 61 array('http://example.com/image1', 'http://example.com/image2')); 62 $this->assertSame('SM123', $msg->sid); 63 } 64 65 function testBadMessageThrowsException() { 66 $this->setExpectedException('Services_Twilio_RestException'); 67 $http = m::mock(new Services_Twilio_TinyHttp); 68 $http->shouldReceive('post')->once() 69 ->with('/2010-04-01/Accounts/AC123/Messages.json', $this->formHeaders, 70 'From=%2B1222&To=%2B44123&Body=' . str_repeat('hi', 801)) 71 ->andReturn(array(400, array('Content-Type' => 'application/json'), 72 json_encode(array( 73 'status' => '400', 74 'message' => 'Too long', 75 )) 76 )); 77 $client = new Services_Twilio('AC123', '123', null, $http); 78 $msg = $client->account->messages->sendMessage('+1222', '+44123', str_repeat('hi', 801)); 79 } 80 81 function testRawCreate() { 82 $http = m::mock(new Services_Twilio_TinyHttp); 83 $http->shouldReceive('post')->once() 84 ->with('/2010-04-01/Accounts/AC123/Messages.json', $this->formHeaders, 85 'From=%2B1222&To=%2B44123&MediaUrl=http%3A%2F%2Fexample.com%2Fimage1&MediaUrl=http%3A%2F%2Fexample.com%2Fimage2') 86 ->andReturn(array(200, array('Content-Type' => 'application/json'), 87 json_encode(array('sid' => 'SM123')) 88 )); 89 $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); 90 $msg = $client->account->messages->create(array( 91 'From' => '+1222', 92 'To' => '+44123', 93 'MediaUrl' => array('http://example.com/image1', 'http://example.com/image2') 94 )); 95 $this->assertSame('SM123', $msg->sid); 96 } 97 98 function testDeleteMessage() { 99 $http = m::mock(new Services_Twilio_TinyHttp); 100 $http->shouldReceive('delete')->once() 101 ->with('/2010-04-01/Accounts/AC123/Messages/ME123.json') 102 ->andReturn(array(204, array('Content-Type' => 'application/json'), '' 103 )); 104 $client = new Services_Twilio('AC123', '123', null, $http); 105 $client->account->messages->delete('ME123'); 106 } 107 108 function testNewline() { 109 $http = m::mock(new Services_Twilio_TinyHttp); 110 $http->shouldReceive('post')->once() 111 ->with('/2010-04-01/Accounts/AC123/Messages.json', $this->formHeaders, 112 'Body=Hello%0A%0AHello') 113 ->andReturn(array(200, array('Content-Type' => 'application/json'), 114 json_encode(array('sid' => 'SM123')) 115 )); 116 $client = new Services_Twilio('AC123', '123', '2010-04-01', $http); 117 $msg = $client->account->messages->create(array( 118 'Body' => "Hello\n\nHello" 119 )); 120 $this->assertSame('SM123', $msg->sid); 121 } 122 } 123
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 |