From 5184d9c9ace152adfb85e3be881e0ac385ca4dbb Mon Sep 17 00:00:00 2001 From: Braunson Yager Date: Mon, 15 Jul 2019 16:51:54 -0400 Subject: [PATCH 1/4] Added clientRef method to set the client reference --- src/Messages/NexmoMessage.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Messages/NexmoMessage.php b/src/Messages/NexmoMessage.php index 293cf03..c4685f7 100644 --- a/src/Messages/NexmoMessage.php +++ b/src/Messages/NexmoMessage.php @@ -25,6 +25,13 @@ class NexmoMessage */ public $type = 'text'; + /** + * The client reference. + * + * @var string + */ + public $client_ref = ''; + /** * Create a new message instance. * @@ -73,4 +80,17 @@ public function unicode() return $this; } + + /** + * Set the client reference (up to 40 characters) + * + * @param string $client_ref + * @return $this + */ + public function clientRef($client_ref) + { + $this->client_ref = $client_ref; + + return $this; + } } From 641358629915af11b9b69a28e02d8c5d279bcd7e Mon Sep 17 00:00:00 2001 From: Braunson Yager Date: Mon, 15 Jul 2019 16:59:19 -0400 Subject: [PATCH 2/4] Updated to include client_ref in the message --- src/Channels/NexmoSmsChannel.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Channels/NexmoSmsChannel.php b/src/Channels/NexmoSmsChannel.php index fecbedd..d46dabe 100644 --- a/src/Channels/NexmoSmsChannel.php +++ b/src/Channels/NexmoSmsChannel.php @@ -59,6 +59,7 @@ public function send($notifiable, Notification $notification) 'from' => $message->from ?: $this->from, 'to' => $to, 'text' => trim($message->content), + 'client_ref' => $message->client_ref, ]); } } From c34618cc84a6b274fc1d470d1011496223aa159e Mon Sep 17 00:00:00 2001 From: Braunson Yager Date: Mon, 15 Jul 2019 17:02:18 -0400 Subject: [PATCH 3/4] Update NexmoMessage.php --- src/Messages/NexmoMessage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Messages/NexmoMessage.php b/src/Messages/NexmoMessage.php index c4685f7..36a1aad 100644 --- a/src/Messages/NexmoMessage.php +++ b/src/Messages/NexmoMessage.php @@ -82,7 +82,7 @@ public function unicode() } /** - * Set the client reference (up to 40 characters) + * Set the client reference (up to 40 characters). * * @param string $client_ref * @return $this From 638d1cc0c247aec239b4c2ac403e04cf0762ba34 Mon Sep 17 00:00:00 2001 From: Braunson Yager Date: Sun, 28 Jul 2019 18:52:06 -0400 Subject: [PATCH 4/4] Updated code style, added new test, fixed broken tests --- src/Channels/NexmoSmsChannel.php | 2 +- src/Messages/NexmoMessage.php | 8 +++---- tests/NotificationNexmoChannelTest.php | 30 ++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/Channels/NexmoSmsChannel.php b/src/Channels/NexmoSmsChannel.php index d46dabe..16eb6df 100644 --- a/src/Channels/NexmoSmsChannel.php +++ b/src/Channels/NexmoSmsChannel.php @@ -59,7 +59,7 @@ public function send($notifiable, Notification $notification) 'from' => $message->from ?: $this->from, 'to' => $to, 'text' => trim($message->content), - 'client_ref' => $message->client_ref, + 'client_ref' => $message->clientRef, ]); } } diff --git a/src/Messages/NexmoMessage.php b/src/Messages/NexmoMessage.php index 36a1aad..ffb49ca 100644 --- a/src/Messages/NexmoMessage.php +++ b/src/Messages/NexmoMessage.php @@ -30,7 +30,7 @@ class NexmoMessage * * @var string */ - public $client_ref = ''; + public $clientRef = ''; /** * Create a new message instance. @@ -84,12 +84,12 @@ public function unicode() /** * Set the client reference (up to 40 characters). * - * @param string $client_ref + * @param string $clientRef * @return $this */ - public function clientRef($client_ref) + public function clientRef($clientRef) { - $this->client_ref = $client_ref; + $this->clientRef = $clientRef; return $this; } diff --git a/tests/NotificationNexmoChannelTest.php b/tests/NotificationNexmoChannelTest.php index ce378ba..6847d90 100644 --- a/tests/NotificationNexmoChannelTest.php +++ b/tests/NotificationNexmoChannelTest.php @@ -31,6 +31,7 @@ public function testSmsIsSentViaNexmo() 'from' => '4444444444', 'to' => '5555555555', 'text' => 'this is my message', + 'client_ref' => '', ]); $channel->send($notifiable, $notification); @@ -50,6 +51,27 @@ public function testSmsIsSentViaNexmoWithCustomFrom() 'from' => '5554443333', 'to' => '5555555555', 'text' => 'this is my message', + 'client_ref' => '', + ]); + + $channel->send($notifiable, $notification); + } + + public function testSmsIsSentViaNexmoWithCustomFromAndClientRef() + { + $notification = new NotificationNexmoChannelTestCustomFromAndClientRefNotification; + $notifiable = new NotificationNexmoChannelTestNotifiable; + + $channel = new NexmoSmsChannel( + $nexmo = m::mock(Client::class), '4444444444' + ); + + $nexmo->shouldReceive('message->send')->with([ + 'type' => 'unicode', + 'from' => '5554443333', + 'to' => '5555555555', + 'text' => 'this is my message', + 'client_ref' => '11', ]); $channel->send($notifiable, $notification); @@ -78,3 +100,11 @@ public function toNexmo($notifiable) return (new NexmoMessage('this is my message'))->from('5554443333')->unicode(); } } + +class NotificationNexmoChannelTestCustomFromAndClientRefNotification extends Notification +{ + public function toNexmo($notifiable) + { + return (new NexmoMessage('this is my message'))->from('5554443333')->unicode()->clientRef('11'); + } +}