Skip to content

Commit

Permalink
Add PHPUnit test suite. Tweak test to make SURE every character in gs…
Browse files Browse the repository at this point in the history
…m7 is covered. Add docs in readme (#409)
  • Loading branch information
SecondeJK committed May 22, 2023
1 parent 9cc0d27 commit bb29ae2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ foreach($response as $index => $data){

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

### Detecting Encoding Type

You can use a static `isGsm7()` method within the SMS Client code to determine whether to send the message using
GSM-7 encoding or Unicode. Here is an example:

```php
$sms = new \Vonage\SMS\Message\SMS('123', '456', 'is this gsm7?');

if (Vonage\SMS\Message\SMS::isGsm7($text)) {
$sms->setType('text');
} else {
$sms->setType('unicode');
}
```

### Receiving a Message

Inbound messages are [sent to your application as a webhook][doc_inbound]. The Client library provides a way to
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<testsuite name="messages">
<directory>test/Messages</directory>
</testsuite>
<testsuite name="sms">
<directory>test/SMS</directory>
</testsuite>
</testsuites>
<php>
<ini name='error_reporting' value='E_ALL' />
Expand Down
34 changes: 25 additions & 9 deletions test/SMS/Message/SMSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,23 +170,39 @@ public function testDLTInfoDoesNotAppearsWhenNotSet(): void
}

/**
* @dataProvider unicodeStringDataProvider
* @dataProvider entireGsm7CharSetProvider
* @return void
*/
public function testGsm7Identification(string $message, bool $expectedGsm7): void
{
$this->assertEquals($expectedGsm7, SMS::isGsm7($message));
}

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

$return = [];

foreach ($gsm7Characters as $character) {
$return[] = [$character, true];
}

$return[] = ['This is a text with some tasty characters: [test]', true];
$return[] = ['This is a Çotcha', true];
$return[] = ['This is also a çotcha', false];
$return[] = ['日本語でボナージュ', false];

return $return;
}
}

0 comments on commit bb29ae2

Please sign in to comment.