Skip to content

Commit

Permalink
Check for the existence of toMobilyWs method
Browse files Browse the repository at this point in the history
  • Loading branch information
alhoqbani committed Aug 15, 2017
1 parent af25a7d commit 93246b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/MobilyWsChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace NotificationChannels\MobilyWs;

use Illuminate\Events\Dispatcher;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Events\NotificationFailed;
use Illuminate\Notifications\Notification;
use NotificationChannels\MobilyWs\Exceptions\CouldNotSendNotification;

class MobilyWsChannel
Expand Down Expand Up @@ -39,6 +39,9 @@ public function __construct(MobilyWsApi $mobilyWs, Dispatcher $events)
*/
public function send($notifiable, Notification $notification)
{
if ( ! method_exists($notification, 'toMobilyWs')) {
throw CouldNotSendNotification::withErrorMessage('MobilyWs notifications must have toMobilyWs method');
}
$number = $notifiable->routeNotificationFor('MobilyWs') ?: $notifiable->phone_number;

$response = $this->api->send([
Expand Down
14 changes: 14 additions & 0 deletions tests/ChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ public function it_throw_an_exception_when_mobily_ws_return_an_error()
$this->fail('CouldNotSendNotification exception was not raised');
}

/** @test */
public function it_throw_an_exception_when_toMobilyWs_method_does_not_exist()
{
try {
$this->channel->send($this->notifiable, new Notification());
} catch (CouldNotSendNotification $e) {
$this->assertContains('MobilyWs notifications must have toMobilyWs method', $e->getMessage());
return;
}

$this->fail('CouldNotSendNotification exception was not raised');

}

}

class TestNotifiable
Expand Down

0 comments on commit 93246b5

Please sign in to comment.