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,14 +26,14 @@ 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
+ ));
34
+
35
+ $ vonage -> shouldReceive ( ' sms->send ' )
36
+ -> with (IsEqual:: equalTo ( $ mockSms ) )
35
37
->once ();
36
38
37
39
$ channel ->send ($ notifiable , $ notification );
@@ -40,14 +42,12 @@ public function testSmsIsSentViaVonage()
40
42
public function testSmsIsSentViaVonageWithCustomClient ()
41
43
{
42
44
$ 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
- ])
45
+ $ customVonage ->shouldReceive ('sms->send ' )
46
+ ->with (IsEqual::equalTo (new SMS (
47
+ '5555555555 ' ,
48
+ '4444444444 ' ,
49
+ 'this is my message '
50
+ )))
51
51
->once ();
52
52
53
53
$ notification = new NotificationVonageSmsChannelTestCustomClientNotification ($ customVonage );
@@ -57,7 +57,7 @@ public function testSmsIsSentViaVonageWithCustomClient()
57
57
$ vonage = m::mock (Client::class), '4444444444 '
58
58
);
59
59
60
- $ vonage ->shouldNotReceive ('message ->send ' );
60
+ $ vonage ->shouldNotReceive ('sms ->send ' );
61
61
62
62
$ channel ->send ($ notifiable , $ notification );
63
63
}
@@ -71,14 +71,14 @@ public function testSmsIsSentViaVonageWithCustomFrom()
71
71
$ vonage = m::mock (Client::class), '4444444444 '
72
72
);
73
73
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
- ] )
74
+ $ mockSms = ( new SMS (
75
+ ' 5555555555 ' ,
76
+ ' 5554443333 ' ,
77
+ ' this is my message '
78
+ ));
79
+
80
+ $ vonage -> shouldReceive ( ' sms->send ' )
81
+ -> with (IsEqual:: equalTo ( $ mockSms ) )
82
82
->once ();
83
83
84
84
$ channel ->send ($ notifiable , $ notification );
@@ -87,14 +87,16 @@ public function testSmsIsSentViaVonageWithCustomFrom()
87
87
public function testSmsIsSentViaVonageWithCustomFromAndClient ()
88
88
{
89
89
$ 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
- ])
90
+
91
+ $ mockSms = new SMS (
92
+ '5555555555 ' ,
93
+ '5554443333 ' ,
94
+ 'this is my message ' ,
95
+ 'unicode '
96
+ );
97
+
98
+ $ customVonage ->shouldReceive ('sms->send ' )
99
+ ->with (IsEqual::equalTo ($ mockSms ))
98
100
->once ();
99
101
100
102
$ notification = new NotificationVonageSmsChannelTestCustomFromAndClientNotification ($ customVonage );
@@ -104,7 +106,7 @@ public function testSmsIsSentViaVonageWithCustomFromAndClient()
104
106
$ vonage = m::mock (Client::class), '4444444444 '
105
107
);
106
108
107
- $ vonage ->shouldNotReceive ('message ->send ' );
109
+ $ vonage ->shouldNotReceive ('sms ->send ' );
108
110
109
111
$ channel ->send ($ notifiable , $ notification );
110
112
}
@@ -118,14 +120,17 @@ public function testSmsIsSentViaVonageWithCustomFromAndClientRef()
118
120
$ vonage = m::mock (Client::class), '4444444444 '
119
121
);
120
122
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
- ])
123
+ $ mockSms = new SMS (
124
+ '5555555555 ' ,
125
+ '5554443333 ' ,
126
+ 'this is my message ' ,
127
+ 'unicode '
128
+ );
129
+
130
+ $ mockSms ->setClientRef ('11 ' );
131
+
132
+ $ vonage ->shouldReceive ('sms->send ' )
133
+ ->with (IsEqual::equalTo ($ mockSms ))
129
134
->once ();
130
135
131
136
$ channel ->send ($ notifiable , $ notification );
@@ -134,14 +139,18 @@ public function testSmsIsSentViaVonageWithCustomFromAndClientRef()
134
139
public function testSmsIsSentViaVonageWithCustomClientFromAndClientRef ()
135
140
{
136
141
$ 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
- ])
142
+
143
+ $ mockSms = new SMS (
144
+ '5555555555 ' ,
145
+ '5554443333 ' ,
146
+ 'this is my message ' ,
147
+ 'unicode '
148
+ );
149
+
150
+ $ mockSms ->setClientRef ('11 ' );
151
+
152
+ $ customVonage ->shouldReceive ('sms->send ' )
153
+ ->with (IsEqual::equalTo ($ mockSms ))
145
154
->once ();
146
155
147
156
$ notification = new NotificationVonageSmsChannelTestCustomClientFromAndClientRefNotification ($ customVonage );
@@ -151,7 +160,7 @@ public function testSmsIsSentViaVonageWithCustomClientFromAndClientRef()
151
160
$ vonage = m::mock (Client::class), '4444444444 '
152
161
);
153
162
154
- $ vonage ->shouldNotReceive ('message ->send ' );
163
+ $ vonage ->shouldNotReceive ('sms ->send ' );
155
164
156
165
$ channel ->send ($ notifiable , $ notification );
157
166
}
@@ -165,16 +174,17 @@ public function testCallbackIsApplied()
165
174
$ vonage = m::mock (Client::class), '4444444444 '
166
175
);
167
176
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 ();
177
+ $ mockSms = (new SMS (
178
+ '5555555555 ' ,
179
+ '4444444444 ' ,
180
+ 'this is my message '
181
+ ));
182
+
183
+ $ mockSms ->setDeliveryReceiptCallback ('https://example.com ' );
184
+
185
+ $ vonage ->shouldReceive ('sms->send ' )
186
+ ->with (IsEqual::equalTo ($ mockSms ))
187
+ ->once ();
178
188
179
189
$ channel ->send ($ notifiable , $ notification );
180
190
}
@@ -269,7 +279,6 @@ class NotificationVonageSmsChannelTestCallback extends Notification
269
279
{
270
280
public function toVonage ($ notifiable )
271
281
{
272
- return (new VonageMessage ('this is my message ' ))
273
- ->statusCallback ('https://example.com ' );
282
+ return (new VonageMessage ('this is my message ' ))->statusCallback ('https://example.com ' );
274
283
}
275
284
}
0 commit comments