From badafb0473d6c9c9eb82bd0f824bb6344a42678a Mon Sep 17 00:00:00 2001 From: James Seconde Date: Fri, 6 Jan 2023 10:06:22 +0000 Subject: [PATCH 1/4] Changed the SMS channel to use the SMS client instead of the legacy message client. --- src/Channels/VonageSmsChannel.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Channels/VonageSmsChannel.php b/src/Channels/VonageSmsChannel.php index 4539a3e..6926c03 100644 --- a/src/Channels/VonageSmsChannel.php +++ b/src/Channels/VonageSmsChannel.php @@ -5,6 +5,7 @@ use Illuminate\Notifications\Messages\VonageMessage; use Illuminate\Notifications\Notification; use Vonage\Client as VonageClient; +use Vonage\SMS\Message\SMS; class VonageSmsChannel { @@ -54,18 +55,18 @@ public function send($notifiable, Notification $notification) $message = new VonageMessage($message); } - $payload = [ - 'type' => $message->type, - 'from' => $message->from ?: $this->from, - 'to' => $to, - 'text' => trim($message->content), - 'client-ref' => $message->clientReference, - ]; + $vonageSms = new SMS( + $to, + $message->from ?: $this->from, + trim($message->content) + ); + + $vonageSms->setClientRef($message->clientReference); if ($message->statusCallback) { - $payload['callback'] = $message->statusCallback; + $vonageSms->setDeliveryReceiptCallback($message->statusCallback); } - return ($message->client ?? $this->client)->message()->send($payload); + return ($message->client ?? $this->client)->sms()->send($vonageSms); } } From 449c2544c00d06b2c3b7db0a64d25634b52bcb33 Mon Sep 17 00:00:00 2001 From: James Seconde Date: Fri, 6 Jan 2023 10:06:49 +0000 Subject: [PATCH 2/4] Fixed/modified tests to reflect new logic --- tests/Unit/Channels/VonageSmsChannelTest.php | 135 ++++++++++--------- 1 file changed, 72 insertions(+), 63 deletions(-) diff --git a/tests/Unit/Channels/VonageSmsChannelTest.php b/tests/Unit/Channels/VonageSmsChannelTest.php index e9c7343..5000e62 100644 --- a/tests/Unit/Channels/VonageSmsChannelTest.php +++ b/tests/Unit/Channels/VonageSmsChannelTest.php @@ -2,6 +2,7 @@ namespace Illuminate\Notifications\Tests\Unit\Channels; +use Hamcrest\Core\IsEqual; use Illuminate\Notifications\Channels\VonageSmsChannel; use Illuminate\Notifications\Messages\VonageMessage; use Illuminate\Notifications\Notifiable; @@ -10,6 +11,7 @@ use Mockery as m; use PHPUnit\Framework\TestCase; use Vonage\Client; +use Vonage\SMS\Message\SMS; class VonageSmsChannelTest extends TestCase { @@ -24,14 +26,14 @@ public function testSmsIsSentViaVonage() $vonage = m::mock(Client::class), '4444444444' ); - $vonage->shouldReceive('message->send') - ->with([ - 'type' => 'text', - 'from' => '4444444444', - 'to' => '5555555555', - 'text' => 'this is my message', - 'client-ref' => '', - ]) + $mockSms = (new SMS( + '5555555555', + '4444444444', + 'this is my message' + )); + + $vonage->shouldReceive('sms->send') + ->with(IsEqual::equalTo($mockSms)) ->once(); $channel->send($notifiable, $notification); @@ -40,14 +42,12 @@ public function testSmsIsSentViaVonage() public function testSmsIsSentViaVonageWithCustomClient() { $customVonage = m::mock(Client::class); - $customVonage->shouldReceive('message->send') - ->with([ - 'type' => 'text', - 'from' => '4444444444', - 'to' => '5555555555', - 'text' => 'this is my message', - 'client-ref' => '', - ]) + $customVonage->shouldReceive('sms->send') + ->with(IsEqual::equalTo(new SMS( + '5555555555', + '4444444444', + 'this is my message' + ))) ->once(); $notification = new NotificationVonageSmsChannelTestCustomClientNotification($customVonage); @@ -57,7 +57,7 @@ public function testSmsIsSentViaVonageWithCustomClient() $vonage = m::mock(Client::class), '4444444444' ); - $vonage->shouldNotReceive('message->send'); + $vonage->shouldNotReceive('sms->send'); $channel->send($notifiable, $notification); } @@ -71,14 +71,14 @@ public function testSmsIsSentViaVonageWithCustomFrom() $vonage = m::mock(Client::class), '4444444444' ); - $vonage->shouldReceive('message->send') - ->with([ - 'type' => 'unicode', - 'from' => '5554443333', - 'to' => '5555555555', - 'text' => 'this is my message', - 'client-ref' => '', - ]) + $mockSms = (new SMS( + '5555555555', + '5554443333', + 'this is my message' + )); + + $vonage->shouldReceive('sms->send') + ->with(IsEqual::equalTo($mockSms)) ->once(); $channel->send($notifiable, $notification); @@ -87,14 +87,16 @@ public function testSmsIsSentViaVonageWithCustomFrom() public function testSmsIsSentViaVonageWithCustomFromAndClient() { $customVonage = m::mock(Client::class); - $customVonage->shouldReceive('message->send') - ->with([ - 'type' => 'unicode', - 'from' => '5554443333', - 'to' => '5555555555', - 'text' => 'this is my message', - 'client-ref' => '', - ]) + + $mockSms = new SMS( + '5555555555', + '5554443333', + 'this is my message', + 'unicode' + ); + + $customVonage->shouldReceive('sms->send') + ->with(IsEqual::equalTo($mockSms)) ->once(); $notification = new NotificationVonageSmsChannelTestCustomFromAndClientNotification($customVonage); @@ -104,7 +106,7 @@ public function testSmsIsSentViaVonageWithCustomFromAndClient() $vonage = m::mock(Client::class), '4444444444' ); - $vonage->shouldNotReceive('message->send'); + $vonage->shouldNotReceive('sms->send'); $channel->send($notifiable, $notification); } @@ -118,14 +120,17 @@ public function testSmsIsSentViaVonageWithCustomFromAndClientRef() $vonage = m::mock(Client::class), '4444444444' ); - $vonage->shouldReceive('message->send') - ->with([ - 'type' => 'unicode', - 'from' => '5554443333', - 'to' => '5555555555', - 'text' => 'this is my message', - 'client-ref' => '11', - ]) + $mockSms = new SMS( + '5555555555', + '5554443333', + 'this is my message', + 'unicode' + ); + + $mockSms->setClientRef('11'); + + $vonage->shouldReceive('sms->send') + ->with(IsEqual::equalTo($mockSms)) ->once(); $channel->send($notifiable, $notification); @@ -134,14 +139,18 @@ public function testSmsIsSentViaVonageWithCustomFromAndClientRef() public function testSmsIsSentViaVonageWithCustomClientFromAndClientRef() { $customVonage = m::mock(Client::class); - $customVonage->shouldReceive('message->send') - ->with([ - 'type' => 'unicode', - 'from' => '5554443333', - 'to' => '5555555555', - 'text' => 'this is my message', - 'client-ref' => '11', - ]) + + $mockSms = new SMS( + '5555555555', + '5554443333', + 'this is my message', + 'unicode' + ); + + $mockSms->setClientRef('11'); + + $customVonage->shouldReceive('sms->send') + ->with(IsEqual::equalTo($mockSms)) ->once(); $notification = new NotificationVonageSmsChannelTestCustomClientFromAndClientRefNotification($customVonage); @@ -151,7 +160,7 @@ public function testSmsIsSentViaVonageWithCustomClientFromAndClientRef() $vonage = m::mock(Client::class), '4444444444' ); - $vonage->shouldNotReceive('message->send'); + $vonage->shouldNotReceive('sms->send'); $channel->send($notifiable, $notification); } @@ -165,16 +174,17 @@ public function testCallbackIsApplied() $vonage = m::mock(Client::class), '4444444444' ); - $vonage->shouldReceive('message->send') - ->with([ - 'type' => 'text', - 'from' => '4444444444', - 'to' => '5555555555', - 'text' => 'this is my message', - 'client-ref' => '', - 'callback' => 'https://example.com', - ]) - ->once(); + $mockSms = (new SMS( + '5555555555', + '4444444444', + 'this is my message' + )); + + $mockSms->setDeliveryReceiptCallback('https://example.com'); + + $vonage->shouldReceive('sms->send') + ->with(IsEqual::equalTo($mockSms)) + ->once(); $channel->send($notifiable, $notification); } @@ -269,7 +279,6 @@ class NotificationVonageSmsChannelTestCallback extends Notification { public function toVonage($notifiable) { - return (new VonageMessage('this is my message')) - ->statusCallback('https://example.com'); + return (new VonageMessage('this is my message'))->statusCallback('https://example.com'); } } From a1f2fcbcb86106b4d7290059eacb1bf58fd4ceba Mon Sep 17 00:00:00 2001 From: James Seconde Date: Wed, 1 Feb 2023 10:13:07 +0000 Subject: [PATCH 3/4] Rehashed PR to use new SMS Client, bring in v4 of the core library to make GSM-7 default. --- composer.json | 2 +- src/Channels/VonageSmsChannel.php | 5 ++- tests/Unit/Channels/VonageSmsChannelTest.php | 44 ++++++++++++++++---- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 661868c..d2743f6 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "php": "^8.0", "illuminate/notifications": "^8.0|^9.0", "illuminate/support": "^8.0|^9.0", - "vonage/client-core": "^3.0" + "vonage/client-core": "^4.0.2" }, "require-dev": { "guzzlehttp/guzzle": "^7.2", diff --git a/src/Channels/VonageSmsChannel.php b/src/Channels/VonageSmsChannel.php index 6926c03..af4d74d 100644 --- a/src/Channels/VonageSmsChannel.php +++ b/src/Channels/VonageSmsChannel.php @@ -41,7 +41,7 @@ public function __construct(VonageClient $client, $from) * * @param mixed $notifiable * @param \Illuminate\Notifications\Notification $notification - * @return \Vonage\Message\Message + * @return \Vonage\SMS\Collection|null */ public function send($notifiable, Notification $notification) { @@ -58,7 +58,8 @@ public function send($notifiable, Notification $notification) $vonageSms = new SMS( $to, $message->from ?: $this->from, - trim($message->content) + trim($message->content), + $message->type ); $vonageSms->setClientRef($message->clientReference); diff --git a/tests/Unit/Channels/VonageSmsChannelTest.php b/tests/Unit/Channels/VonageSmsChannelTest.php index 5000e62..1200164 100644 --- a/tests/Unit/Channels/VonageSmsChannelTest.php +++ b/tests/Unit/Channels/VonageSmsChannelTest.php @@ -29,7 +29,8 @@ public function testSmsIsSentViaVonage() $mockSms = (new SMS( '5555555555', '4444444444', - 'this is my message' + 'this is my message', + 'text' )); $vonage->shouldReceive('sms->send') @@ -39,6 +40,29 @@ public function testSmsIsSentViaVonage() $channel->send($notifiable, $notification); } + public function testSmsWillSendAsUnicode() + { + $notification = new NotificationVonageUnicodeSmsChannelTestNotification; + $notifiable = new NotificationVonageSmsChannelTestNotifiable; + + $channel = new VonageSmsChannel( + $vonage = m::mock(Client::class), '4444444444' + ); + + $mockSms = (new SMS( + '5555555555', + '4444444444', + 'this is my message', + 'unicode' + )); + + $vonage->shouldReceive('sms->send') + ->with(IsEqual::equalTo($mockSms)) + ->once(); + + $channel->send($notifiable, $notification); + } + public function testSmsIsSentViaVonageWithCustomClient() { $customVonage = m::mock(Client::class); @@ -92,7 +116,6 @@ public function testSmsIsSentViaVonageWithCustomFromAndClient() '5555555555', '5554443333', 'this is my message', - 'unicode' ); $customVonage->shouldReceive('sms->send') @@ -124,7 +147,6 @@ public function testSmsIsSentViaVonageWithCustomFromAndClientRef() '5555555555', '5554443333', 'this is my message', - 'unicode' ); $mockSms->setClientRef('11'); @@ -144,7 +166,6 @@ public function testSmsIsSentViaVonageWithCustomClientFromAndClientRef() '5555555555', '5554443333', 'this is my message', - 'unicode' ); $mockSms->setClientRef('11'); @@ -210,6 +231,14 @@ public function toVonage($notifiable) } } +class NotificationVonageUnicodeSmsChannelTestNotification extends Notification +{ + public function toVonage($notifiable) + { + return (new VonageMessage('this is my message'))->unicode(); + } +} + class NotificationVonageSmsChannelTestCustomClientNotification extends Notification { private $client; @@ -229,7 +258,7 @@ class NotificationVonageSmsChannelTestCustomFromNotification extends Notificatio { public function toVonage($notifiable) { - return (new VonageMessage('this is my message'))->from('5554443333')->unicode(); + return (new VonageMessage('this is my message'))->from('5554443333'); } } @@ -244,7 +273,7 @@ public function __construct(Client $client) public function toVonage($notifiable) { - return (new VonageMessage('this is my message'))->from('5554443333')->unicode()->usingClient($this->client); + return (new VonageMessage('this is my message'))->from('5554443333')->usingClient($this->client); } } @@ -252,7 +281,7 @@ class NotificationVonageSmsChannelTestCustomFromAndClientRefNotification extends { public function toVonage($notifiable) { - return (new VonageMessage('this is my message'))->from('5554443333')->unicode()->clientReference('11'); + return (new VonageMessage('this is my message'))->from('5554443333')->clientReference('11'); } } @@ -269,7 +298,6 @@ public function toVonage($notifiable) { return (new VonageMessage('this is my message')) ->from('5554443333') - ->unicode() ->clientReference('11') ->usingClient($this->client); } From 31b17ff039411e95ae38993e84909632cdda1318 Mon Sep 17 00:00:00 2001 From: James Seconde Date: Fri, 3 Feb 2023 08:15:25 +0000 Subject: [PATCH 4/4] core version bump to squash bug --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7cabb92..01078d4 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "php": "^8.0", "illuminate/notifications": "^8.0|^9.0|^10.0", "illuminate/support": "^8.0|^9.0|^10.0", - "vonage/client-core": "^4.0.2" + "vonage/client-core": "^4.0.4" }, "require-dev": { "guzzlehttp/guzzle": "^7.2",