|
7 | 7 | use Mockery;
|
8 | 8 | use NotificationChannels\Twilio\TwilioCallMessage;
|
9 | 9 | use NotificationChannels\Twilio\TwilioChannel;
|
| 10 | +use NotificationChannels\Twilio\TwilioConfig; |
10 | 11 | use NotificationChannels\Twilio\TwilioSmsMessage;
|
11 | 12 | use PHPUnit_Framework_TestCase;
|
12 | 13 | use NotificationChannels\Twilio\Twilio;
|
@@ -44,43 +45,85 @@ public function it_can_send_a_sms_message()
|
44 | 45 | $message = TwilioSmsMessage::create('Message text');
|
45 | 46 | $this->notification->shouldReceive('toTwilio')->andReturn($message);
|
46 | 47 |
|
47 |
| - $twilio = new Twilio($this->twilioService, '+31612345678'); |
| 48 | + $config = new TwilioConfig([ |
| 49 | + 'from' => '+31612345678' |
| 50 | + ]); |
| 51 | + $twilio = new Twilio($this->twilioService, $config); |
| 52 | + $channel = new TwilioChannel($twilio, $this->events); |
| 53 | + |
| 54 | + $this->smsMessageWillBeSentToTwilioWith('+31612345678', '+22222222222', 'Message text', null, []); |
| 55 | + |
| 56 | + $channel->send(new NotifiableWithAttribute(), $this->notification); |
| 57 | + } |
48 | 58 |
|
| 59 | + /** @test */ |
| 60 | + public function it_can_send_a_sms_message_using_service() |
| 61 | + { |
| 62 | + $message = TwilioSmsMessage::create('Message text'); |
| 63 | + $this->notification->shouldReceive('toTwilio')->andReturn($message); |
| 64 | + |
| 65 | + $config = new TwilioConfig([ |
| 66 | + 'from' => '+31612345678', |
| 67 | + 'sms_service_sid' => '0123456789' |
| 68 | + ]); |
| 69 | + $twilio = new Twilio($this->twilioService, $config); |
49 | 70 | $channel = new TwilioChannel($twilio, $this->events);
|
50 | 71 |
|
51 |
| - $this->smsMessageWillBeSentToTwilioWith('+31612345678', '+22222222222', 'Message text'); |
| 72 | + $this->smsMessageWillBeSentToTwilioWith('+31612345678', '+22222222222', 'Message text', null, [ |
| 73 | + 'MessagingServiceSid' => '0123456789' |
| 74 | + ]); |
52 | 75 |
|
53 | 76 | $channel->send(new NotifiableWithAttribute(), $this->notification);
|
54 | 77 | }
|
55 | 78 |
|
| 79 | + /** @test */ |
| 80 | + public function it_can_send_a_sms_message_using_alphanumeric_sender() |
| 81 | + { |
| 82 | + $message = TwilioSmsMessage::create('Message text'); |
| 83 | + $this->notification->shouldReceive('toTwilio')->andReturn($message); |
| 84 | + |
| 85 | + $config = new TwilioConfig([ |
| 86 | + 'from' => '+31612345678', |
| 87 | + 'alphanumeric_sender' => 'TwilioTest' |
| 88 | + ]); |
| 89 | + $twilio = new Twilio($this->twilioService, $config); |
| 90 | + $channel = new TwilioChannel($twilio, $this->events); |
| 91 | + |
| 92 | + $this->smsMessageWillBeSentToTwilioWith('TwilioTest', '+33333333333', 'Message text', null, []); |
| 93 | + |
| 94 | + $channel->send(new NotifiableWithAlphanumericSender(), $this->notification); |
| 95 | + } |
| 96 | + |
56 | 97 | /** @test */
|
57 | 98 | public function it_can_make_a_call()
|
58 | 99 | {
|
59 | 100 | $message = TwilioCallMessage::create('http://example.com');
|
60 | 101 | $this->notification->shouldReceive('toTwilio')->andReturn($message);
|
61 | 102 |
|
62 |
| - $twilio = new Twilio($this->twilioService, '+31612345678'); |
63 |
| - |
| 103 | + $config = new TwilioConfig([ |
| 104 | + 'from' => '+31612345678' |
| 105 | + ]); |
| 106 | + $twilio = new Twilio($this->twilioService, $config); |
64 | 107 | $channel = new TwilioChannel($twilio, $this->events);
|
65 | 108 |
|
66 | 109 | $this->callWillBeSentToTwilioWith('+31612345678', '+22222222222', 'http://example.com');
|
67 | 110 |
|
68 | 111 | $channel->send(new NotifiableWithAttribute(), $this->notification);
|
69 | 112 | }
|
70 | 113 |
|
71 |
| - protected function smsMessageWillBeSentToTwilioWith($from, $to, $message) |
| 114 | + protected function smsMessageWillBeSentToTwilioWith(...$args) |
72 | 115 | {
|
73 | 116 | $this->twilioService->account->messages->shouldReceive('sendMessage')
|
74 | 117 | ->atLeast()->once()
|
75 |
| - ->with($from, $to, $message) |
| 118 | + ->with(...$args) |
76 | 119 | ->andReturn(true);
|
77 | 120 | }
|
78 | 121 |
|
79 |
| - protected function callWillBeSentToTwilioWith($from, $to, $url) |
| 122 | + protected function callWillBeSentToTwilioWith(...$args) |
80 | 123 | {
|
81 | 124 | $this->twilioService->account->calls->shouldReceive('create')
|
82 | 125 | ->atLeast()->once()
|
83 |
| - ->with($from, $to, $url) |
| 126 | + ->with(...$args) |
84 | 127 | ->andReturn(true);
|
85 | 128 | }
|
86 | 129 | }
|
0 commit comments