Skip to content

Commit bb29ae2

Browse files
authored
Add PHPUnit test suite. Tweak test to make SURE every character in gsm7 is covered. Add docs in readme (#409)
1 parent 9cc0d27 commit bb29ae2

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,21 @@ foreach($response as $index => $data){
112112

113113
The [send example][send_example] also has full working examples.
114114

115+
### Detecting Encoding Type
116+
117+
You can use a static `isGsm7()` method within the SMS Client code to determine whether to send the message using
118+
GSM-7 encoding or Unicode. Here is an example:
119+
120+
```php
121+
$sms = new \Vonage\SMS\Message\SMS('123', '456', 'is this gsm7?');
122+
123+
if (Vonage\SMS\Message\SMS::isGsm7($text)) {
124+
$sms->setType('text');
125+
} else {
126+
$sms->setType('unicode');
127+
}
128+
```
129+
115130
### Receiving a Message
116131

117132
Inbound messages are [sent to your application as a webhook][doc_inbound]. The Client library provides a way to

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
<testsuite name="messages">
3030
<directory>test/Messages</directory>
3131
</testsuite>
32+
<testsuite name="sms">
33+
<directory>test/SMS</directory>
34+
</testsuite>
3235
</testsuites>
3336
<php>
3437
<ini name='error_reporting' value='E_ALL' />

test/SMS/Message/SMSTest.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,23 +170,39 @@ public function testDLTInfoDoesNotAppearsWhenNotSet(): void
170170
}
171171

172172
/**
173-
* @dataProvider unicodeStringDataProvider
173+
* @dataProvider entireGsm7CharSetProvider
174174
* @return void
175175
*/
176176
public function testGsm7Identification(string $message, bool $expectedGsm7): void
177177
{
178178
$this->assertEquals($expectedGsm7, SMS::isGsm7($message));
179179
}
180180

181-
public function unicodeStringDataProvider(): array
181+
public function entireGsm7CharSetProvider(): array
182182
{
183-
return [
184-
['this is a text', true],
185-
['This is a text with some tasty characters: [test]', true],
186-
['This is also a GSM7 text', true],
187-
['This is a Çotcha', true],
188-
['This is also a çotcha', false],
189-
['日本語でボナージュ', false],
183+
$gsm7Characters = [
184+
"@", "£", "$", "¥", "è", "é", "ù", "ì", "ò", "Ç", "\n", "Ø", "ø", "\r", "Å",
185+
"å", "\u0394", "_", "\u03a6", "\u0393", "\u039b", "\u03a9", "\u03a0", "\u03a8",
186+
"\u03a3", "\u0398", "\u039e", "\u00a0", "Æ", "æ", "ß", "É", " ", "!", "\"", "#",
187+
"¤", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", "0", "1", "2", "3",
188+
"4", "5", "6", "7", "8", "9", ":", ";", "<", "=", ">", "?", "¡", "A", "B", "C",
189+
"D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
190+
"T", "U", "V", "W", "X", "Y", "Z", "Ä", "Ö", "Ñ", "Ü", "§", "¿", "a", "b", "c",
191+
"d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
192+
"t", "u", "v", "w", "x", "y", "z", "ä", "ö", "ñ", "ü", "à",
190193
];
194+
195+
$return = [];
196+
197+
foreach ($gsm7Characters as $character) {
198+
$return[] = [$character, true];
199+
}
200+
201+
$return[] = ['This is a text with some tasty characters: [test]', true];
202+
$return[] = ['This is a Çotcha', true];
203+
$return[] = ['This is also a çotcha', false];
204+
$return[] = ['日本語でボナージュ', false];
205+
206+
return $return;
191207
}
192208
}

0 commit comments

Comments
 (0)