Skip to content

Commit 6c469f2

Browse files
test: add tests and examples for SMS module
1 parent 997134f commit 6c469f2

2 files changed

Lines changed: 61 additions & 11 deletions

File tree

readme.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,45 @@ if ($disponibilita->availability > 0) {
180180
error_log(var_dump($e));
181181
}
182182
}
183+
```
184+
185+
## Modulo SMS
186+
* `getRecipients`
187+
* `getMessage`
188+
* `sendMore`
189+
* `sendOne`
190+
191+
### Inviare un SMS
192+
Per inviare un SMS, per prima cosa definiamo i destinatari:
193+
194+
```php
195+
$recipient = '+39-3939989741';
196+
// OR
197+
$recipients = [
198+
[
199+
'number' => '+39-3939989741',
200+
'fields' => ['nome' => 'NomeDestinatario']
201+
]
202+
];
203+
```
204+
205+
Possiamo ora procedere ad inviare un SMS:
206+
```php
207+
208+
try {
209+
$singleSms = $this->openapi->SMS->sendOne('Nome del mittente', $recipient, 'lorem ipsum', null, 1, null);
210+
} catch (\OpenApi\classes\exception\OpenApiConnectionsException $e) {
211+
throw 'Non è stato possibile recapitare il messaggio';
212+
}
213+
```
214+
215+
Possiamo anche speficiare i prefissi in modo indipendente:
216+
```php
217+
$this->openapi->SMS->sendOne('Nome del mittente', '3939989741', 'lorem ipsum', '+42', 1, null);
218+
```
219+
220+
O passare delle opzioni
221+
```php
222+
$options = ['timestamp_send' => '2021-04-20']
223+
$this->openapi->SMS->sendOne('Nome del mittente', '3939989741', 'lorem ipsum', '+42', 1, $options);
183224
```

tests/ClientTest.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public function __construct() {
3737
"GET:imprese.altravia.com/gruppoiva",
3838
"GET:comuni.openapi.it/cap",
3939
"GET:comuni.openapi.it/istat",
40-
"GET:comuni.openapi.it/regioni",
4140
"GET:comuni.openapi.it/province",
41+
"GET:comuni.openapi.it/regioni",
4242
"GET:comuni.openapi.it/catastale",
4343
"GET:ws.ufficiopostale.com/tracking",
4444
"POST:geocoding.realgest.it/geocode",
@@ -95,12 +95,12 @@ public function testClientInstance() {
9595
// $this->assertIsObject($Pec);
9696
// }
9797

98-
public function testMarche() {
99-
$marca = $this->openapi->marcheTemporali->availability('infocert', 1);
100-
$comprata = $this->openapi->marcheTemporali->purcahse('infocert', 1);
98+
// public function testMarche() {
99+
// $marca = $this->openapi->marcheTemporali->availability('infocert', 1);
100+
// $comprata = $this->openapi->marcheTemporali->purcahse('infocert', 1);
101101

102-
$this->assertIsInt($marca->availability);
103-
}
102+
// $this->assertIsInt($marca->availability);
103+
// }
104104

105105
// public function testGeocoding() {
106106
// // Prendi informazioni sul cap 00132
@@ -135,11 +135,20 @@ public function testMarche() {
135135
// $raccomandata->creaRaccomandataByData($data);
136136
// }
137137

138-
// public function testSms() {
139-
// $singleSms = $this->openapi->SMS->sendOne('prova', '3939989741', 'messaggio di prova', null, 1, null, true);
140-
// $this->assertIsArray($singleSms);
141-
// var_dump($singleSms);
142-
// }
138+
public function testSms() {
139+
$recipients = [
140+
[
141+
'number' => '+39-3939989741',
142+
'fields' => ['nome' => 'NomeDestinatario']
143+
]
144+
];
145+
$singleSms = $this->openapi->SMS->sendOne('test', '+39-3939989741', 'prova', null, 1, null, true);
146+
147+
$message = $this->openapi->SMS->getMessage($singleSms->data->id);
148+
149+
$this->assertEquals(true, $singleSms->success);
150+
$this->assertEquals(true, $message['success']);
151+
}
143152

144153
// public function testVisura() {
145154
// // $visura = new VisRequest('eccbc87e4b5ce2fe28308fd9f2a7baf3');

0 commit comments

Comments
 (0)