2
2
3
3
namespace Illuminate \Notifications \Tests \Unit \Channels ;
4
4
5
+ use Hamcrest \Core \IsEqual ;
5
6
use Illuminate \Notifications \Channels \VonageSmsChannel ;
6
7
use Illuminate \Notifications \Messages \VonageMessage ;
7
8
use Illuminate \Notifications \Notifiable ;
10
11
use Mockery as m ;
11
12
use PHPUnit \Framework \TestCase ;
12
13
use Vonage \Client ;
14
+ use Vonage \SMS \Message \SMS ;
13
15
14
16
class VonageSmsChannelTest extends TestCase
15
17
{
@@ -24,30 +26,52 @@ public function testSmsIsSentViaVonage()
24
26
$ vonage = m::mock (Client::class), '4444444444 '
25
27
);
26
28
27
- $ vonage ->shouldReceive ('message->send ' )
28
- ->with ([
29
- 'type ' => 'text ' ,
30
- 'from ' => '4444444444 ' ,
31
- 'to ' => '5555555555 ' ,
32
- 'text ' => 'this is my message ' ,
33
- 'client-ref ' => '' ,
34
- ])
29
+ $ mockSms = (new SMS (
30
+ '5555555555 ' ,
31
+ '4444444444 ' ,
32
+ 'this is my message ' ,
33
+ 'text '
34
+ ));
35
+
36
+ $ vonage ->shouldReceive ('sms->send ' )
37
+ ->with (IsEqual::equalTo ($ mockSms ))
35
38
->once ();
36
39
37
40
$ channel ->send ($ notifiable , $ notification );
38
41
}
39
42
43
+ public function testSmsWillSendAsUnicode ()
44
+ {
45
+ $ notification = new NotificationVonageUnicodeSmsChannelTestNotification ;
46
+ $ notifiable = new NotificationVonageSmsChannelTestNotifiable ;
47
+
48
+ $ channel = new VonageSmsChannel (
49
+ $ vonage = m::mock (Client::class), '4444444444 '
50
+ );
51
+
52
+ $ mockSms = (new SMS (
53
+ '5555555555 ' ,
54
+ '4444444444 ' ,
55
+ 'this is my message ' ,
56
+ 'unicode '
57
+ ));
58
+
59
+ $ vonage ->shouldReceive ('sms->send ' )
60
+ ->with (IsEqual::equalTo ($ mockSms ))
61
+ ->once ();
62
+
63
+ $ channel ->send ($ notifiable , $ notification );
64
+ }
65
+
40
66
public function testSmsIsSentViaVonageWithCustomClient ()
41
67
{
42
68
$ customVonage = m::mock (Client::class);
43
- $ customVonage ->shouldReceive ('message->send ' )
44
- ->with ([
45
- 'type ' => 'text ' ,
46
- 'from ' => '4444444444 ' ,
47
- 'to ' => '5555555555 ' ,
48
- 'text ' => 'this is my message ' ,
49
- 'client-ref ' => '' ,
50
- ])
69
+ $ customVonage ->shouldReceive ('sms->send ' )
70
+ ->with (IsEqual::equalTo (new SMS (
71
+ '5555555555 ' ,
72
+ '4444444444 ' ,
73
+ 'this is my message '
74
+ )))
51
75
->once ();
52
76
53
77
$ notification = new NotificationVonageSmsChannelTestCustomClientNotification ($ customVonage );
@@ -57,7 +81,7 @@ public function testSmsIsSentViaVonageWithCustomClient()
57
81
$ vonage = m::mock (Client::class), '4444444444 '
58
82
);
59
83
60
- $ vonage ->shouldNotReceive ('message ->send ' );
84
+ $ vonage ->shouldNotReceive ('sms ->send ' );
61
85
62
86
$ channel ->send ($ notifiable , $ notification );
63
87
}
@@ -71,14 +95,14 @@ public function testSmsIsSentViaVonageWithCustomFrom()
71
95
$ vonage = m::mock (Client::class), '4444444444 '
72
96
);
73
97
74
- $ vonage -> shouldReceive ( ' message->send ' )
75
- -> with ([
76
- ' type ' => ' unicode ' ,
77
- ' from ' => ' 5554443333 ' ,
78
- ' to ' => ' 5555555555 ' ,
79
- ' text ' => ' this is my message ' ,
80
- ' client-ref ' => '' ,
81
- ] )
98
+ $ mockSms = ( new SMS (
99
+ ' 5555555555 ' ,
100
+ ' 5554443333 ' ,
101
+ ' this is my message '
102
+ ));
103
+
104
+ $ vonage -> shouldReceive ( ' sms->send ' )
105
+ -> with (IsEqual:: equalTo ( $ mockSms ) )
82
106
->once ();
83
107
84
108
$ channel ->send ($ notifiable , $ notification );
@@ -87,14 +111,15 @@ public function testSmsIsSentViaVonageWithCustomFrom()
87
111
public function testSmsIsSentViaVonageWithCustomFromAndClient ()
88
112
{
89
113
$ customVonage = m::mock (Client::class);
90
- $ customVonage ->shouldReceive ('message->send ' )
91
- ->with ([
92
- 'type ' => 'unicode ' ,
93
- 'from ' => '5554443333 ' ,
94
- 'to ' => '5555555555 ' ,
95
- 'text ' => 'this is my message ' ,
96
- 'client-ref ' => '' ,
97
- ])
114
+
115
+ $ mockSms = new SMS (
116
+ '5555555555 ' ,
117
+ '5554443333 ' ,
118
+ 'this is my message ' ,
119
+ );
120
+
121
+ $ customVonage ->shouldReceive ('sms->send ' )
122
+ ->with (IsEqual::equalTo ($ mockSms ))
98
123
->once ();
99
124
100
125
$ notification = new NotificationVonageSmsChannelTestCustomFromAndClientNotification ($ customVonage );
@@ -104,7 +129,7 @@ public function testSmsIsSentViaVonageWithCustomFromAndClient()
104
129
$ vonage = m::mock (Client::class), '4444444444 '
105
130
);
106
131
107
- $ vonage ->shouldNotReceive ('message ->send ' );
132
+ $ vonage ->shouldNotReceive ('sms ->send ' );
108
133
109
134
$ channel ->send ($ notifiable , $ notification );
110
135
}
@@ -118,14 +143,16 @@ public function testSmsIsSentViaVonageWithCustomFromAndClientRef()
118
143
$ vonage = m::mock (Client::class), '4444444444 '
119
144
);
120
145
121
- $ vonage ->shouldReceive ('message->send ' )
122
- ->with ([
123
- 'type ' => 'unicode ' ,
124
- 'from ' => '5554443333 ' ,
125
- 'to ' => '5555555555 ' ,
126
- 'text ' => 'this is my message ' ,
127
- 'client-ref ' => '11 ' ,
128
- ])
146
+ $ mockSms = new SMS (
147
+ '5555555555 ' ,
148
+ '5554443333 ' ,
149
+ 'this is my message ' ,
150
+ );
151
+
152
+ $ mockSms ->setClientRef ('11 ' );
153
+
154
+ $ vonage ->shouldReceive ('sms->send ' )
155
+ ->with (IsEqual::equalTo ($ mockSms ))
129
156
->once ();
130
157
131
158
$ channel ->send ($ notifiable , $ notification );
@@ -134,14 +161,17 @@ public function testSmsIsSentViaVonageWithCustomFromAndClientRef()
134
161
public function testSmsIsSentViaVonageWithCustomClientFromAndClientRef ()
135
162
{
136
163
$ customVonage = m::mock (Client::class);
137
- $ customVonage ->shouldReceive ('message->send ' )
138
- ->with ([
139
- 'type ' => 'unicode ' ,
140
- 'from ' => '5554443333 ' ,
141
- 'to ' => '5555555555 ' ,
142
- 'text ' => 'this is my message ' ,
143
- 'client-ref ' => '11 ' ,
144
- ])
164
+
165
+ $ mockSms = new SMS (
166
+ '5555555555 ' ,
167
+ '5554443333 ' ,
168
+ 'this is my message ' ,
169
+ );
170
+
171
+ $ mockSms ->setClientRef ('11 ' );
172
+
173
+ $ customVonage ->shouldReceive ('sms->send ' )
174
+ ->with (IsEqual::equalTo ($ mockSms ))
145
175
->once ();
146
176
147
177
$ notification = new NotificationVonageSmsChannelTestCustomClientFromAndClientRefNotification ($ customVonage );
@@ -151,7 +181,7 @@ public function testSmsIsSentViaVonageWithCustomClientFromAndClientRef()
151
181
$ vonage = m::mock (Client::class), '4444444444 '
152
182
);
153
183
154
- $ vonage ->shouldNotReceive ('message ->send ' );
184
+ $ vonage ->shouldNotReceive ('sms ->send ' );
155
185
156
186
$ channel ->send ($ notifiable , $ notification );
157
187
}
@@ -165,16 +195,17 @@ public function testCallbackIsApplied()
165
195
$ vonage = m::mock (Client::class), '4444444444 '
166
196
);
167
197
168
- $ vonage ->shouldReceive ('message->send ' )
169
- ->with ([
170
- 'type ' => 'text ' ,
171
- 'from ' => '4444444444 ' ,
172
- 'to ' => '5555555555 ' ,
173
- 'text ' => 'this is my message ' ,
174
- 'client-ref ' => '' ,
175
- 'callback ' => 'https://example.com ' ,
176
- ])
177
- ->once ();
198
+ $ mockSms = (new SMS (
199
+ '5555555555 ' ,
200
+ '4444444444 ' ,
201
+ 'this is my message '
202
+ ));
203
+
204
+ $ mockSms ->setDeliveryReceiptCallback ('https://example.com ' );
205
+
206
+ $ vonage ->shouldReceive ('sms->send ' )
207
+ ->with (IsEqual::equalTo ($ mockSms ))
208
+ ->once ();
178
209
179
210
$ channel ->send ($ notifiable , $ notification );
180
211
}
@@ -200,6 +231,14 @@ public function toVonage($notifiable)
200
231
}
201
232
}
202
233
234
+ class NotificationVonageUnicodeSmsChannelTestNotification extends Notification
235
+ {
236
+ public function toVonage ($ notifiable )
237
+ {
238
+ return (new VonageMessage ('this is my message ' ))->unicode ();
239
+ }
240
+ }
241
+
203
242
class NotificationVonageSmsChannelTestCustomClientNotification extends Notification
204
243
{
205
244
private $ client ;
@@ -219,7 +258,7 @@ class NotificationVonageSmsChannelTestCustomFromNotification extends Notificatio
219
258
{
220
259
public function toVonage ($ notifiable )
221
260
{
222
- return (new VonageMessage ('this is my message ' ))->from ('5554443333 ' )-> unicode () ;
261
+ return (new VonageMessage ('this is my message ' ))->from ('5554443333 ' );
223
262
}
224
263
}
225
264
@@ -234,15 +273,15 @@ public function __construct(Client $client)
234
273
235
274
public function toVonage ($ notifiable )
236
275
{
237
- return (new VonageMessage ('this is my message ' ))->from ('5554443333 ' )->unicode ()-> usingClient ($ this ->client );
276
+ return (new VonageMessage ('this is my message ' ))->from ('5554443333 ' )->usingClient ($ this ->client );
238
277
}
239
278
}
240
279
241
280
class NotificationVonageSmsChannelTestCustomFromAndClientRefNotification extends Notification
242
281
{
243
282
public function toVonage ($ notifiable )
244
283
{
245
- return (new VonageMessage ('this is my message ' ))->from ('5554443333 ' )->unicode ()-> clientReference ('11 ' );
284
+ return (new VonageMessage ('this is my message ' ))->from ('5554443333 ' )->clientReference ('11 ' );
246
285
}
247
286
}
248
287
@@ -259,7 +298,6 @@ public function toVonage($notifiable)
259
298
{
260
299
return (new VonageMessage ('this is my message ' ))
261
300
->from ('5554443333 ' )
262
- ->unicode ()
263
301
->clientReference ('11 ' )
264
302
->usingClient ($ this ->client );
265
303
}
@@ -269,7 +307,6 @@ class NotificationVonageSmsChannelTestCallback extends Notification
269
307
{
270
308
public function toVonage ($ notifiable )
271
309
{
272
- return (new VonageMessage ('this is my message ' ))
273
- ->statusCallback ('https://example.com ' );
310
+ return (new VonageMessage ('this is my message ' ))->statusCallback ('https://example.com ' );
274
311
}
275
312
}
0 commit comments