1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the smsmode-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2019 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Bundle\SmsModeBundle\Tests\EventListener; |
13
|
|
|
|
14
|
|
|
use RuntimeException; |
15
|
|
|
use Throwable; |
16
|
|
|
use WBW\Bundle\SmsModeBundle\Event\AccountBalanceEvent; |
17
|
|
|
use WBW\Bundle\SmsModeBundle\Event\AddingContactEvent; |
18
|
|
|
use WBW\Bundle\SmsModeBundle\Event\CheckingSmsMessageStatusEvent; |
19
|
|
|
use WBW\Bundle\SmsModeBundle\Event\CreatingApiKeyEvent; |
20
|
|
|
use WBW\Bundle\SmsModeBundle\Event\CreatingSubAccountEvent; |
21
|
|
|
use WBW\Bundle\SmsModeBundle\Event\DeletingSmsEvent; |
22
|
|
|
use WBW\Bundle\SmsModeBundle\Event\DeletingSubAccountEvent; |
23
|
|
|
use WBW\Bundle\SmsModeBundle\Event\DeliveryReportEvent; |
24
|
|
|
use WBW\Bundle\SmsModeBundle\Event\RetrievingSmsReplyEvent; |
25
|
|
|
use WBW\Bundle\SmsModeBundle\Event\SendingSmsBatchEvent; |
26
|
|
|
use WBW\Bundle\SmsModeBundle\Event\SendingSmsMessageEvent; |
27
|
|
|
use WBW\Bundle\SmsModeBundle\Event\SendingTextToSpeechSmsEvent; |
28
|
|
|
use WBW\Bundle\SmsModeBundle\Event\SendingUnicodeSmsEvent; |
29
|
|
|
use WBW\Bundle\SmsModeBundle\Event\SentSmsMessageListEvent; |
30
|
|
|
use WBW\Bundle\SmsModeBundle\Event\TransferringCreditsEvent; |
31
|
|
|
use WBW\Bundle\SmsModeBundle\EventListener\DefaultEventListener; |
32
|
|
|
use WBW\Bundle\SmsModeBundle\Tests\AbstractTestCase; |
33
|
|
|
use WBW\Library\SmsMode\Request\AccountBalanceRequest; |
34
|
|
|
use WBW\Library\SmsMode\Request\AddingContactRequest; |
35
|
|
|
use WBW\Library\SmsMode\Request\CheckingSmsMessageStatusRequest; |
36
|
|
|
use WBW\Library\SmsMode\Request\CreatingApiKeyRequest; |
37
|
|
|
use WBW\Library\SmsMode\Request\CreatingSubAccountRequest; |
38
|
|
|
use WBW\Library\SmsMode\Request\DeletingSmsRequest; |
39
|
|
|
use WBW\Library\SmsMode\Request\DeletingSubAccountRequest; |
40
|
|
|
use WBW\Library\SmsMode\Request\DeliveryReportRequest; |
41
|
|
|
use WBW\Library\SmsMode\Request\RetrievingSmsReplyRequest; |
42
|
|
|
use WBW\Library\SmsMode\Request\SendingSmsBatchRequest; |
43
|
|
|
use WBW\Library\SmsMode\Request\SendingSmsMessageRequest; |
44
|
|
|
use WBW\Library\SmsMode\Request\SendingTextToSpeechSmsRequest; |
45
|
|
|
use WBW\Library\SmsMode\Request\SendingUnicodeSmsRequest; |
46
|
|
|
use WBW\Library\SmsMode\Request\SentSmsMessageListRequest; |
47
|
|
|
use WBW\Library\SmsMode\Request\TransferringCreditsRequest; |
48
|
|
|
use WBW\Library\SmsMode\Response\AccountBalanceResponse; |
49
|
|
|
use WBW\Library\SmsMode\Response\AddingContactResponse; |
50
|
|
|
use WBW\Library\SmsMode\Response\CheckingSmsMessageStatusResponse; |
51
|
|
|
use WBW\Library\SmsMode\Response\CreatingApiKeyResponse; |
52
|
|
|
use WBW\Library\SmsMode\Response\CreatingSubAccountResponse; |
53
|
|
|
use WBW\Library\SmsMode\Response\DeletingSmsResponse; |
54
|
|
|
use WBW\Library\SmsMode\Response\DeletingSubAccountResponse; |
55
|
|
|
use WBW\Library\SmsMode\Response\DeliveryReportResponse; |
56
|
|
|
use WBW\Library\SmsMode\Response\RetrievingSmsReplyResponse; |
57
|
|
|
use WBW\Library\SmsMode\Response\SendingSmsBatchResponse; |
58
|
|
|
use WBW\Library\SmsMode\Response\SendingSmsMessageResponse; |
59
|
|
|
use WBW\Library\SmsMode\Response\SendingTextToSpeechSmsResponse; |
60
|
|
|
use WBW\Library\SmsMode\Response\SendingUnicodeSmsResponse; |
61
|
|
|
use WBW\Library\SmsMode\Response\SentSmsMessageListResponse; |
62
|
|
|
use WBW\Library\SmsMode\Response\TransferringCreditsResponse; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Default event listener test. |
66
|
|
|
* |
67
|
|
|
* @author webeweb <https://github.com/webeweb> |
68
|
|
|
* @package WBW\Bundle\SmsModeBundle\Tests\EventListener |
69
|
|
|
*/ |
70
|
|
|
class DefaultEventListenerTest extends AbstractTestCase { |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* sMsmode event listener. |
74
|
|
|
* |
75
|
|
|
* @var DefaultEventListener |
76
|
|
|
*/ |
77
|
|
|
private $smsModeEventListener; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* {@inheritDoc} |
81
|
|
|
*/ |
82
|
|
|
protected function setUp(): void { |
83
|
|
|
parent::setUp(); |
84
|
|
|
|
85
|
|
|
// Set a sMsmode event listener. |
86
|
|
|
$this->smsModeEventListener = new DefaultEventListener($this->logger); |
87
|
|
|
$this->smsModeEventListener->setPseudo("pseudo"); |
88
|
|
|
$this->smsModeEventListener->setPass("pass"); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Test onAccountBalance() |
93
|
|
|
* |
94
|
|
|
* @return void |
95
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
96
|
|
|
*/ |
97
|
|
|
public function testOnAccountBalance(): void { |
98
|
|
|
|
99
|
|
|
// Set an Account balance event mock. |
100
|
|
|
$accountBalanceEvent = new AccountBalanceEvent(); |
101
|
|
|
|
102
|
|
|
$obj = $this->smsModeEventListener; |
103
|
|
|
|
104
|
|
|
$res = $obj->onAccountBalance($accountBalanceEvent); |
105
|
|
|
$this->assertSame($accountBalanceEvent, $res); |
106
|
|
|
|
107
|
|
|
$this->assertInstanceOf(AccountBalanceRequest::class, $res->getRequest()); |
108
|
|
|
$this->assertInstanceOf(AccountBalanceResponse::class, $res->getResponse()); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Test onAccountBalance() |
113
|
|
|
* |
114
|
|
|
* @return void |
115
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
116
|
|
|
*/ |
117
|
|
|
public function testOnAccountBalanceWithRuntimeException(): void { |
118
|
|
|
|
119
|
|
|
// Set an Account balance event mock. |
120
|
|
|
$accountBalanceEvent = new AccountBalanceEvent(); |
121
|
|
|
|
122
|
|
|
$obj = new DefaultEventListener($this->logger); |
123
|
|
|
|
124
|
|
|
try { |
125
|
|
|
|
126
|
|
|
$obj->onAccountBalance($accountBalanceEvent); |
127
|
|
|
} catch (Throwable $ex) { |
128
|
|
|
|
129
|
|
|
$this->assertInstanceOf(RuntimeException::class, $ex); |
130
|
|
|
$this->assertEquals(DefaultEventListener::RUNTIME_EXCEPTION_MESSAGE, $ex->getMessage()); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Test onAddingContact() |
136
|
|
|
* |
137
|
|
|
* @return void |
138
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
139
|
|
|
*/ |
140
|
|
|
public function testOnAddingContact(): void { |
141
|
|
|
|
142
|
|
|
// Set an Adding contact event mock. |
143
|
|
|
$addingContactEvent = new AddingContactEvent($this->addingContact); |
144
|
|
|
|
145
|
|
|
$obj = $this->smsModeEventListener; |
146
|
|
|
|
147
|
|
|
$res = $obj->onAddingContact($addingContactEvent); |
148
|
|
|
$this->assertSame($addingContactEvent, $res); |
149
|
|
|
|
150
|
|
|
$this->assertInstanceOf(AddingContactRequest::class, $res->getRequest()); |
151
|
|
|
$this->assertInstanceOf(AddingContactResponse::class, $res->getResponse()); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Test onAddingContact() |
156
|
|
|
* |
157
|
|
|
* @return void |
158
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
159
|
|
|
*/ |
160
|
|
|
public function testOnAddingContactWithRuntimeException(): void { |
161
|
|
|
|
162
|
|
|
// Set an Adding contact event mock. |
163
|
|
|
$addingContactEvent = new AddingContactEvent($this->addingContact); |
164
|
|
|
|
165
|
|
|
$obj = new DefaultEventListener($this->logger); |
166
|
|
|
|
167
|
|
|
try { |
168
|
|
|
|
169
|
|
|
$obj->onAddingContact($addingContactEvent); |
170
|
|
|
} catch (Throwable $ex) { |
171
|
|
|
|
172
|
|
|
$this->assertInstanceOf(RuntimeException::class, $ex); |
173
|
|
|
$this->assertEquals(DefaultEventListener::RUNTIME_EXCEPTION_MESSAGE, $ex->getMessage()); |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Test onCheckingSmsMessageStatus() |
179
|
|
|
* |
180
|
|
|
* @return void |
181
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
182
|
|
|
*/ |
183
|
|
|
public function testOnCheckingSmsMessageStatus(): void { |
184
|
|
|
|
185
|
|
|
// Set a Checking SMS message status event mock. |
186
|
|
|
$checkingSmsMessageStatusEvent = new CheckingSmsMessageStatusEvent($this->checkingSmsMessageStatus); |
187
|
|
|
|
188
|
|
|
$obj = $this->smsModeEventListener; |
189
|
|
|
|
190
|
|
|
$res = $obj->onCheckingSmsMessageStatus($checkingSmsMessageStatusEvent); |
191
|
|
|
$this->assertSame($checkingSmsMessageStatusEvent, $res); |
192
|
|
|
|
193
|
|
|
$this->assertInstanceOf(CheckingSmsMessageStatusRequest::class, $res->getRequest()); |
194
|
|
|
$this->assertInstanceOf(CheckingSmsMessageStatusResponse::class, $res->getResponse()); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Test onCheckingSmsMessageStatus() |
199
|
|
|
* |
200
|
|
|
* @return void |
201
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
202
|
|
|
*/ |
203
|
|
|
public function testOnCheckingSmsMessageStatusWithRuntimeException(): void { |
204
|
|
|
|
205
|
|
|
// Set an Checking SMS message status event mock. |
206
|
|
|
$checkingSmsMessageStatusEvent = new CheckingSmsMessageStatusEvent($this->checkingSmsMessageStatus); |
207
|
|
|
|
208
|
|
|
$obj = new DefaultEventListener($this->logger); |
209
|
|
|
|
210
|
|
|
try { |
211
|
|
|
|
212
|
|
|
$obj->onCheckingSmsMessageStatus($checkingSmsMessageStatusEvent); |
213
|
|
|
} catch (Throwable $ex) { |
214
|
|
|
|
215
|
|
|
$this->assertInstanceOf(RuntimeException::class, $ex); |
216
|
|
|
$this->assertEquals(DefaultEventListener::RUNTIME_EXCEPTION_MESSAGE, $ex->getMessage()); |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Test onCreatingApiKey() |
222
|
|
|
* |
223
|
|
|
* @return void |
224
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
225
|
|
|
*/ |
226
|
|
|
public function testOnCreatingApiKey(): void { |
227
|
|
|
|
228
|
|
|
// Set a Creating API key event mock. |
229
|
|
|
$creatingApiKeyEvent = new CreatingApiKeyEvent(); |
230
|
|
|
|
231
|
|
|
$obj = $this->smsModeEventListener; |
232
|
|
|
|
233
|
|
|
$res = $obj->onCreatingApiKey($creatingApiKeyEvent); |
234
|
|
|
$this->assertSame($creatingApiKeyEvent, $res); |
235
|
|
|
|
236
|
|
|
$this->assertInstanceOf(CreatingApiKeyRequest::class, $res->getRequest()); |
237
|
|
|
$this->assertInstanceOf(CreatingApiKeyResponse::class, $res->getResponse()); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Test onCreatingApiKey() |
242
|
|
|
* |
243
|
|
|
* @return void |
244
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
245
|
|
|
*/ |
246
|
|
|
public function testOnCreatingApiKeyWithRuntimeException(): void { |
247
|
|
|
|
248
|
|
|
// Set a Creating API key event mock. |
249
|
|
|
$creatingApiKeyEvent = new CreatingApiKeyEvent(); |
250
|
|
|
|
251
|
|
|
$obj = new DefaultEventListener($this->logger); |
252
|
|
|
|
253
|
|
|
try { |
254
|
|
|
|
255
|
|
|
$obj->onCreatingApiKey($creatingApiKeyEvent); |
256
|
|
|
} catch (Throwable $ex) { |
257
|
|
|
|
258
|
|
|
$this->assertInstanceOf(RuntimeException::class, $ex); |
259
|
|
|
$this->assertEquals(DefaultEventListener::RUNTIME_EXCEPTION_MESSAGE, $ex->getMessage()); |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* Test onCreatingSubAccount() |
265
|
|
|
* |
266
|
|
|
* @return void |
267
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
268
|
|
|
*/ |
269
|
|
|
public function testOnCreatingSubAccount(): void { |
270
|
|
|
|
271
|
|
|
// Set a Creating sub-account event mock. |
272
|
|
|
$creatingSubAccountEvent = new CreatingSubAccountEvent($this->creatingSubAccount); |
273
|
|
|
|
274
|
|
|
$obj = $this->smsModeEventListener; |
275
|
|
|
|
276
|
|
|
$res = $obj->onCreatingSubAccount($creatingSubAccountEvent); |
277
|
|
|
$this->assertSame($creatingSubAccountEvent, $res); |
278
|
|
|
|
279
|
|
|
$this->assertInstanceOf(CreatingSubAccountRequest::class, $res->getRequest()); |
280
|
|
|
$this->assertInstanceOf(CreatingSubAccountResponse::class, $res->getResponse()); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* Test onCreatingSubAccount() |
285
|
|
|
* |
286
|
|
|
* @return void |
287
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
288
|
|
|
*/ |
289
|
|
|
public function testOnCreatingSubAccountWithRuntimeException(): void { |
290
|
|
|
|
291
|
|
|
// Set a Creating sub-account event mock. |
292
|
|
|
$creatingSubAccountEvent = new CreatingSubAccountEvent($this->creatingSubAccount); |
293
|
|
|
|
294
|
|
|
$obj = new DefaultEventListener($this->logger); |
295
|
|
|
|
296
|
|
|
try { |
297
|
|
|
|
298
|
|
|
$obj->onCreatingSubAccount($creatingSubAccountEvent); |
299
|
|
|
} catch (Throwable $ex) { |
300
|
|
|
|
301
|
|
|
$this->assertInstanceOf(RuntimeException::class, $ex); |
302
|
|
|
$this->assertEquals(DefaultEventListener::RUNTIME_EXCEPTION_MESSAGE, $ex->getMessage()); |
303
|
|
|
} |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Test onDeletingSms() |
308
|
|
|
* |
309
|
|
|
* @return void |
310
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
311
|
|
|
*/ |
312
|
|
|
public function testOnDeletingSms(): void { |
313
|
|
|
|
314
|
|
|
// Set a Deleting SMS event mock. |
315
|
|
|
$deletingSmsEvent = new DeletingSmsEvent($this->deletingSms); |
316
|
|
|
|
317
|
|
|
$obj = $this->smsModeEventListener; |
318
|
|
|
|
319
|
|
|
$res = $obj->onDeletingSms($deletingSmsEvent); |
320
|
|
|
$this->assertSame($deletingSmsEvent, $res); |
321
|
|
|
|
322
|
|
|
$this->assertInstanceOf(DeletingSmsRequest::class, $res->getRequest()); |
323
|
|
|
$this->assertInstanceOf(DeletingSmsResponse::class, $res->getResponse()); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* Test onDeletingSms() |
328
|
|
|
* |
329
|
|
|
* @return void |
330
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
331
|
|
|
*/ |
332
|
|
|
public function testOnDeletingSmsWithRuntimeException(): void { |
333
|
|
|
|
334
|
|
|
// Set a Deleting SMS event mock. |
335
|
|
|
$deletingSmsEvent = new DeletingSmsEvent($this->deletingSms); |
336
|
|
|
|
337
|
|
|
$obj = new DefaultEventListener($this->logger); |
338
|
|
|
|
339
|
|
|
try { |
340
|
|
|
|
341
|
|
|
$obj->onDeletingSms($deletingSmsEvent); |
342
|
|
|
} catch (Throwable $ex) { |
343
|
|
|
|
344
|
|
|
$this->assertInstanceOf(RuntimeException::class, $ex); |
345
|
|
|
$this->assertEquals(DefaultEventListener::RUNTIME_EXCEPTION_MESSAGE, $ex->getMessage()); |
346
|
|
|
} |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
/** |
350
|
|
|
* Test onDeletingSubAccount() |
351
|
|
|
* |
352
|
|
|
* @return void |
353
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
354
|
|
|
*/ |
355
|
|
|
public function testOnDeletingSubAccount() { |
356
|
|
|
|
357
|
|
|
// Set a Deleting sub-account event mock. |
358
|
|
|
$deletingSubAccountEvent = new DeletingSubAccountEvent($this->deletingSubAccount); |
359
|
|
|
|
360
|
|
|
$obj = $this->smsModeEventListener; |
361
|
|
|
|
362
|
|
|
$res = $obj->onDeletingSubAccount($deletingSubAccountEvent); |
363
|
|
|
$this->assertSame($deletingSubAccountEvent, $res); |
364
|
|
|
|
365
|
|
|
$this->assertInstanceOf(DeletingSubAccountRequest::class, $res->getRequest()); |
366
|
|
|
$this->assertInstanceOf(DeletingSubAccountResponse::class, $res->getResponse()); |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* Test onDeletingSubAccount() |
371
|
|
|
* |
372
|
|
|
* @return void |
373
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
374
|
|
|
*/ |
375
|
|
|
public function testOnDeletingSubAccountWithRuntimeException() { |
376
|
|
|
|
377
|
|
|
// Set a Deleting sub-account event mock. |
378
|
|
|
$deletingSubAccountEvent = new DeletingSubAccountEvent($this->deletingSubAccount); |
379
|
|
|
|
380
|
|
|
$obj = new DefaultEventListener($this->logger); |
381
|
|
|
|
382
|
|
|
try { |
383
|
|
|
|
384
|
|
|
$obj->onDeletingSubAccount($deletingSubAccountEvent); |
385
|
|
|
} catch (Throwable $ex) { |
386
|
|
|
|
387
|
|
|
$this->assertInstanceOf(RuntimeException::class, $ex); |
388
|
|
|
$this->assertEquals(DefaultEventListener::RUNTIME_EXCEPTION_MESSAGE, $ex->getMessage()); |
389
|
|
|
} |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* Test onDeliveryReport() |
394
|
|
|
* |
395
|
|
|
* @return void |
396
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
397
|
|
|
*/ |
398
|
|
|
public function testOnDeliveryReport() { |
399
|
|
|
|
400
|
|
|
// Set a Delivery report event mock. |
401
|
|
|
$deliveryReportEvent = new DeliveryReportEvent($this->deliveryReport); |
402
|
|
|
|
403
|
|
|
$obj = $this->smsModeEventListener; |
404
|
|
|
|
405
|
|
|
$res = $obj->onDeliveryReport($deliveryReportEvent); |
406
|
|
|
$this->assertSame($deliveryReportEvent, $res); |
407
|
|
|
|
408
|
|
|
$this->assertInstanceOf(DeliveryReportRequest::class, $res->getRequest()); |
409
|
|
|
$this->assertInstanceOf(DeliveryReportResponse::class, $res->getResponse()); |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
/** |
413
|
|
|
* Test onDeliveryReport() |
414
|
|
|
* |
415
|
|
|
* @return void |
416
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
417
|
|
|
*/ |
418
|
|
|
public function testOnDeliveryReportWithRuntimeException() { |
419
|
|
|
|
420
|
|
|
// Set a Delivery report event mock. |
421
|
|
|
$deliveryReportEvent = new DeliveryReportEvent($this->deliveryReport); |
422
|
|
|
|
423
|
|
|
$obj = new DefaultEventListener($this->logger); |
424
|
|
|
|
425
|
|
|
try { |
426
|
|
|
|
427
|
|
|
$obj->onDeliveryReport($deliveryReportEvent); |
428
|
|
|
} catch (Throwable $ex) { |
429
|
|
|
|
430
|
|
|
$this->assertInstanceOf(RuntimeException::class, $ex); |
431
|
|
|
$this->assertEquals(DefaultEventListener::RUNTIME_EXCEPTION_MESSAGE, $ex->getMessage()); |
432
|
|
|
} |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
/** |
436
|
|
|
* Test onRetrievingSmsReply() |
437
|
|
|
* |
438
|
|
|
* @return void |
439
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
440
|
|
|
*/ |
441
|
|
|
public function testOnRetrievingSmsReply() { |
442
|
|
|
|
443
|
|
|
// Set a Retrieving SMS reply event mock. |
444
|
|
|
$retrievingSmsReplyEvent = new RetrievingSmsReplyEvent($this->retrievingSmsReply); |
445
|
|
|
|
446
|
|
|
$obj = $this->smsModeEventListener; |
447
|
|
|
|
448
|
|
|
$res = $obj->onRetrievingSmsReply($retrievingSmsReplyEvent); |
449
|
|
|
$this->assertSame($retrievingSmsReplyEvent, $res); |
450
|
|
|
|
451
|
|
|
$this->assertInstanceOf(RetrievingSmsReplyRequest::class, $res->getRequest()); |
452
|
|
|
$this->assertInstanceOf(RetrievingSmsReplyResponse::class, $res->getResponse()); |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
/** |
456
|
|
|
* Test onRetrievingSmsReply() |
457
|
|
|
* |
458
|
|
|
* @return void |
459
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
460
|
|
|
*/ |
461
|
|
|
public function testOnRetrievingSmsReplyWithRuntimeException() { |
462
|
|
|
|
463
|
|
|
// Set a Retrieving SMS reply event mock. |
464
|
|
|
$retrievingSmsReplyEvent = new RetrievingSmsReplyEvent($this->retrievingSmsReply); |
465
|
|
|
|
466
|
|
|
$obj = new DefaultEventListener($this->logger); |
467
|
|
|
|
468
|
|
|
try { |
469
|
|
|
|
470
|
|
|
$obj->onRetrievingSmsReply($retrievingSmsReplyEvent); |
471
|
|
|
} catch (Throwable $ex) { |
472
|
|
|
|
473
|
|
|
$this->assertInstanceOf(RuntimeException::class, $ex); |
474
|
|
|
$this->assertEquals(DefaultEventListener::RUNTIME_EXCEPTION_MESSAGE, $ex->getMessage()); |
475
|
|
|
} |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
/** |
479
|
|
|
* Test onSendingSmsBatch() |
480
|
|
|
* |
481
|
|
|
* @return void |
482
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
483
|
|
|
*/ |
484
|
|
|
public function testOnSendingSmsBatch() { |
485
|
|
|
|
486
|
|
|
// Set a Sending SMS batch event mock. |
487
|
|
|
$sendingSmsBatchEvent = new SendingSmsBatchEvent($this->sendingSmsBatch); |
488
|
|
|
|
489
|
|
|
$obj = $this->smsModeEventListener; |
490
|
|
|
|
491
|
|
|
$res = $obj->onSendingSmsBatch($sendingSmsBatchEvent); |
492
|
|
|
$this->assertSame($sendingSmsBatchEvent, $res); |
493
|
|
|
|
494
|
|
|
$this->assertInstanceOf(SendingSmsBatchRequest::class, $res->getRequest()); |
495
|
|
|
$this->assertInstanceOf(SendingSmsBatchResponse::class, $res->getResponse()); |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
/** |
499
|
|
|
* Test onSendingSmsBatch() |
500
|
|
|
* |
501
|
|
|
* @return void |
502
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
503
|
|
|
*/ |
504
|
|
|
public function testOnSendingSmsBatchWithRuntimeException() { |
505
|
|
|
|
506
|
|
|
// Set a Sending SMS batch event mock. |
507
|
|
|
$sendingSmsBatchEvent = new SendingSmsBatchEvent($this->sendingSmsBatch); |
508
|
|
|
|
509
|
|
|
$obj = new DefaultEventListener($this->logger); |
510
|
|
|
|
511
|
|
|
try { |
512
|
|
|
|
513
|
|
|
$obj->onSendingSmsBatch($sendingSmsBatchEvent); |
514
|
|
|
} catch (Throwable $ex) { |
515
|
|
|
|
516
|
|
|
$this->assertInstanceOf(RuntimeException::class, $ex); |
517
|
|
|
$this->assertEquals(DefaultEventListener::RUNTIME_EXCEPTION_MESSAGE, $ex->getMessage()); |
518
|
|
|
} |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
/** |
522
|
|
|
* Test onSendingSmsMessage() |
523
|
|
|
* |
524
|
|
|
* @return void |
525
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
526
|
|
|
*/ |
527
|
|
|
public function testOnSendingSmsMessage() { |
528
|
|
|
|
529
|
|
|
// Set a Sending SMS message event mock. |
530
|
|
|
$sendingSmsMessageEvent = new SendingSmsMessageEvent($this->sendingSmsMessage); |
531
|
|
|
|
532
|
|
|
$obj = $this->smsModeEventListener; |
533
|
|
|
|
534
|
|
|
$res = $obj->onSendingSmsMessage($sendingSmsMessageEvent); |
535
|
|
|
$this->assertSame($sendingSmsMessageEvent, $res); |
536
|
|
|
|
537
|
|
|
$this->assertInstanceOf(SendingSmsMessageRequest::class, $res->getRequest()); |
538
|
|
|
$this->assertInstanceOf(SendingSmsMessageResponse::class, $res->getResponse()); |
539
|
|
|
} |
540
|
|
|
|
541
|
|
|
/** |
542
|
|
|
* Test onSendingSmsMessage() |
543
|
|
|
* |
544
|
|
|
* @return void |
545
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
546
|
|
|
*/ |
547
|
|
|
public function testOnSendingSmsMessageWithRuntimeException() { |
548
|
|
|
|
549
|
|
|
// Set a Sending SMS message event mock. |
550
|
|
|
$sendingSmsMessageEvent = new SendingSmsMessageEvent($this->sendingSmsMessage); |
551
|
|
|
|
552
|
|
|
$obj = new DefaultEventListener($this->logger); |
553
|
|
|
|
554
|
|
|
try { |
555
|
|
|
|
556
|
|
|
$obj->onSendingSmsMessage($sendingSmsMessageEvent); |
557
|
|
|
} catch (Throwable $ex) { |
558
|
|
|
|
559
|
|
|
$this->assertInstanceOf(RuntimeException::class, $ex); |
560
|
|
|
$this->assertEquals(DefaultEventListener::RUNTIME_EXCEPTION_MESSAGE, $ex->getMessage()); |
561
|
|
|
} |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
/** |
565
|
|
|
* Test onSendingTextToSpeechSms() |
566
|
|
|
* |
567
|
|
|
* @return void |
568
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
569
|
|
|
*/ |
570
|
|
|
public function testOnSendingTextToSpeechSms() { |
571
|
|
|
|
572
|
|
|
// Set a Sending text-to-speech event mock. |
573
|
|
|
$sendingTextToSpeechSmsEvent = new SendingTextToSpeechSmsEvent($this->sendingTextToSpeechSms); |
574
|
|
|
|
575
|
|
|
$obj = $this->smsModeEventListener; |
576
|
|
|
|
577
|
|
|
$res = $obj->onSendingTextToSpeechSms($sendingTextToSpeechSmsEvent); |
578
|
|
|
$this->assertSame($sendingTextToSpeechSmsEvent, $res); |
579
|
|
|
|
580
|
|
|
$this->assertInstanceOf(SendingTextToSpeechSmsRequest::class, $res->getRequest()); |
581
|
|
|
$this->assertInstanceOf(SendingTextToSpeechSmsResponse::class, $res->getResponse()); |
582
|
|
|
} |
583
|
|
|
|
584
|
|
|
/** |
585
|
|
|
* Test onSendingTextToSpeechSms() |
586
|
|
|
* |
587
|
|
|
* @return void |
588
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
589
|
|
|
*/ |
590
|
|
|
public function testOnSendingTextToSpeechSmsWithRuntimeException() { |
591
|
|
|
|
592
|
|
|
// Set a Sending text-to-speech SMS event mock. |
593
|
|
|
$sendingTextToSpeechSmsEvent = new SendingTextToSpeechSmsEvent($this->sendingTextToSpeechSms); |
594
|
|
|
|
595
|
|
|
$obj = new DefaultEventListener($this->logger); |
596
|
|
|
|
597
|
|
|
try { |
598
|
|
|
|
599
|
|
|
$obj->onSendingTextToSpeechSms($sendingTextToSpeechSmsEvent); |
600
|
|
|
} catch (Throwable $ex) { |
601
|
|
|
|
602
|
|
|
$this->assertInstanceOf(RuntimeException::class, $ex); |
603
|
|
|
$this->assertEquals(DefaultEventListener::RUNTIME_EXCEPTION_MESSAGE, $ex->getMessage()); |
604
|
|
|
} |
605
|
|
|
} |
606
|
|
|
|
607
|
|
|
/** |
608
|
|
|
* Test onSendingUnicodeSms() |
609
|
|
|
* |
610
|
|
|
* @return void |
611
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
612
|
|
|
*/ |
613
|
|
|
public function testOnSendingUnicodeSms() { |
614
|
|
|
|
615
|
|
|
// Set a Sending unicode SMS event mock. |
616
|
|
|
$sendingUnicodeSmsEvent = new SendingUnicodeSmsEvent($this->sendingUnicodeSms); |
617
|
|
|
|
618
|
|
|
$obj = $this->smsModeEventListener; |
619
|
|
|
|
620
|
|
|
$res = $obj->onSendingUnicodeSms($sendingUnicodeSmsEvent); |
621
|
|
|
$this->assertSame($sendingUnicodeSmsEvent, $res); |
622
|
|
|
|
623
|
|
|
$this->assertInstanceOf(SendingUnicodeSmsRequest::class, $res->getRequest()); |
624
|
|
|
$this->assertInstanceOf(SendingUnicodeSmsResponse::class, $res->getResponse()); |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
/** |
628
|
|
|
* Test onSendingUnicodeSms() |
629
|
|
|
* |
630
|
|
|
* @return void |
631
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
632
|
|
|
*/ |
633
|
|
|
public function testOnSendingUnicodeSmsWithRuntimeException() { |
634
|
|
|
|
635
|
|
|
// Set a Sending unicode SMS event mock. |
636
|
|
|
$sendingUnicodeSmsEvent = new SendingUnicodeSmsEvent($this->sendingUnicodeSms); |
637
|
|
|
|
638
|
|
|
$obj = new DefaultEventListener($this->logger); |
639
|
|
|
|
640
|
|
|
try { |
641
|
|
|
|
642
|
|
|
$obj->onSendingUnicodeSms($sendingUnicodeSmsEvent); |
643
|
|
|
} catch (Throwable $ex) { |
644
|
|
|
|
645
|
|
|
$this->assertInstanceOf(RuntimeException::class, $ex); |
646
|
|
|
$this->assertEquals(DefaultEventListener::RUNTIME_EXCEPTION_MESSAGE, $ex->getMessage()); |
647
|
|
|
} |
648
|
|
|
} |
649
|
|
|
|
650
|
|
|
/** |
651
|
|
|
* Test onSentSmsMessageList() |
652
|
|
|
* |
653
|
|
|
* @return void |
654
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
655
|
|
|
*/ |
656
|
|
|
public function testOnSentSmsMessageList() { |
657
|
|
|
|
658
|
|
|
// Set a Sent SMS message list event mock. |
659
|
|
|
$sentSmsMessageListEvent = new SentSmsMessageListEvent($this->sentSmsMessageList); |
660
|
|
|
|
661
|
|
|
$obj = $this->smsModeEventListener; |
662
|
|
|
|
663
|
|
|
$res = $obj->onSentSmsMessageList($sentSmsMessageListEvent); |
664
|
|
|
$this->assertSame($sentSmsMessageListEvent, $res); |
665
|
|
|
|
666
|
|
|
$this->assertInstanceOf(SentSmsMessageListRequest::class, $res->getRequest()); |
667
|
|
|
$this->assertInstanceOf(SentSmsMessageListResponse::class, $res->getResponse()); |
668
|
|
|
} |
669
|
|
|
|
670
|
|
|
/** |
671
|
|
|
* Test onSentSmsMessageList() |
672
|
|
|
* |
673
|
|
|
* @return void |
674
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
675
|
|
|
*/ |
676
|
|
|
public function testOnSentSmsMessageListWithRuntimeException() { |
677
|
|
|
|
678
|
|
|
// Set a Sent SMS message list event mock. |
679
|
|
|
$sentSmsMessageListEvent = new SentSmsMessageListEvent($this->sentSmsMessageList); |
680
|
|
|
|
681
|
|
|
$obj = new DefaultEventListener($this->logger); |
682
|
|
|
|
683
|
|
|
try { |
684
|
|
|
|
685
|
|
|
$obj->onSentSmsMessageList($sentSmsMessageListEvent); |
686
|
|
|
} catch (Throwable $ex) { |
687
|
|
|
|
688
|
|
|
$this->assertInstanceOf(RuntimeException::class, $ex); |
689
|
|
|
$this->assertEquals(DefaultEventListener::RUNTIME_EXCEPTION_MESSAGE, $ex->getMessage()); |
690
|
|
|
} |
691
|
|
|
} |
692
|
|
|
|
693
|
|
|
/** |
694
|
|
|
* Test onTransferringCredits() |
695
|
|
|
* |
696
|
|
|
* @return void |
697
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
698
|
|
|
*/ |
699
|
|
|
public function testOnTransferringCredits() { |
700
|
|
|
|
701
|
|
|
// Set a Transferring credits event mock. |
702
|
|
|
$transferringCreditsEvent = new TransferringCreditsEvent($this->transferringCredits); |
703
|
|
|
|
704
|
|
|
$obj = $this->smsModeEventListener; |
705
|
|
|
|
706
|
|
|
$res = $obj->onTransferringCredits($transferringCreditsEvent); |
707
|
|
|
$this->assertSame($transferringCreditsEvent, $res); |
708
|
|
|
|
709
|
|
|
$this->assertInstanceOf(TransferringCreditsRequest::class, $res->getRequest()); |
710
|
|
|
$this->assertInstanceOf(TransferringCreditsResponse::class, $res->getResponse()); |
711
|
|
|
} |
712
|
|
|
|
713
|
|
|
/** |
714
|
|
|
* Test onTransferringCredits() |
715
|
|
|
* |
716
|
|
|
* @return void |
717
|
|
|
* @throws Throwable Throws an exception if an error occurs. |
718
|
|
|
*/ |
719
|
|
|
public function testOnTransferringCreditsWithRuntimeException() { |
720
|
|
|
|
721
|
|
|
// Set a Transferring credits event mock. |
722
|
|
|
$transferringCreditsEvent = new TransferringCreditsEvent($this->transferringCredits); |
723
|
|
|
|
724
|
|
|
$obj = new DefaultEventListener($this->logger); |
725
|
|
|
|
726
|
|
|
try { |
727
|
|
|
|
728
|
|
|
$obj->onTransferringCredits($transferringCreditsEvent); |
729
|
|
|
} catch (Throwable $ex) { |
730
|
|
|
|
731
|
|
|
$this->assertInstanceOf(RuntimeException::class, $ex); |
732
|
|
|
$this->assertEquals(DefaultEventListener::RUNTIME_EXCEPTION_MESSAGE, $ex->getMessage()); |
733
|
|
|
} |
734
|
|
|
} |
735
|
|
|
|
736
|
|
|
/** |
737
|
|
|
* Test setAccessToken() |
738
|
|
|
* |
739
|
|
|
* @return void |
740
|
|
|
*/ |
741
|
|
|
public function testSetAccessToken() { |
742
|
|
|
|
743
|
|
|
$obj = new DefaultEventListener($this->logger); |
744
|
|
|
|
745
|
|
|
$obj->setAccessToken("accessToken"); |
746
|
|
|
$this->assertEquals("accessToken", $obj->getApiProvider()->getAuthentication()->getAccessToken()); |
747
|
|
|
} |
748
|
|
|
|
749
|
|
|
/** |
750
|
|
|
* Test setPass() |
751
|
|
|
* |
752
|
|
|
* @return void |
753
|
|
|
*/ |
754
|
|
|
public function testSetPass() { |
755
|
|
|
|
756
|
|
|
$obj = new DefaultEventListener($this->logger); |
757
|
|
|
|
758
|
|
|
$obj->setPass("pass"); |
759
|
|
|
$this->assertEquals("pass", $obj->getApiProvider()->getAuthentication()->getPass()); |
760
|
|
|
} |
761
|
|
|
|
762
|
|
|
/** |
763
|
|
|
* Test setPseudo() |
764
|
|
|
* |
765
|
|
|
* @return void |
766
|
|
|
*/ |
767
|
|
|
public function testSetPseudo() { |
768
|
|
|
|
769
|
|
|
$obj = new DefaultEventListener($this->logger); |
770
|
|
|
|
771
|
|
|
$obj->setPseudo("pseudo"); |
772
|
|
|
$this->assertEquals("pseudo", $obj->getApiProvider()->getAuthentication()->getPseudo()); |
773
|
|
|
} |
774
|
|
|
|
775
|
|
|
/** |
776
|
|
|
* Test __construct() |
777
|
|
|
* |
778
|
|
|
* @return void |
779
|
|
|
*/ |
780
|
|
|
public function test__construct(): void { |
781
|
|
|
|
782
|
|
|
$this->assertEquals("sMsmode configuration is missing in your app/config/config.yml.\nPlease, add smsmode.accesss_token or smsmode.pseudo and smsmode.pass", DefaultEventListener::RUNTIME_EXCEPTION_MESSAGE); |
783
|
|
|
$this->assertEquals("wbw.smsmode.event_listener.default", DefaultEventListener::SERVICE_NAME); |
784
|
|
|
|
785
|
|
|
$obj = new DefaultEventListener($this->logger); |
786
|
|
|
|
787
|
|
|
$this->assertNotNull($obj->getApiProvider()); |
788
|
|
|
} |
789
|
|
|
} |
790
|
|
|
|