Skip to content

Commit 74b2a45

Browse files
committed
return null explicitly when player_id is empty, added tests for channel return values
1 parent 73cebff commit 74b2a45

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/OneSignalChannel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(OneSignalClient $oneSignal)
2929
public function send($notifiable, Notification $notification)
3030
{
3131
if (! $userIds = $notifiable->routeNotificationFor('OneSignal')) {
32-
return;
32+
return null;
3333
}
3434

3535
$payload = $notification->toOneSignal($notifiable)->toArray();

tests/ChannelTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Berkayk\OneSignal\OneSignalClient;
99
use NotificationChannels\OneSignal\OneSignalChannel;
1010
use NotificationChannels\OneSignal\Exceptions\CouldNotSendNotification;
11+
use Psr\Http\Message\ResponseInterface;
1112

1213
class ChannelTest extends TestCase
1314
{
@@ -52,7 +53,9 @@ public function it_can_send_a_notification()
5253
])
5354
->andReturn($response);
5455

55-
$this->channel->send(new Notifiable(), new TestNotification());
56+
$channel_response = $this->channel->send(new Notifiable(), new TestNotification());
57+
58+
$this->assertInstanceOf(ResponseInterface::class, $channel_response);
5659
}
5760

5861
/** @test */
@@ -104,6 +107,18 @@ public function it_can_send_a_notification_with_email()
104107
])
105108
->andReturn($response);
106109

107-
$this->channel->send(new NotifiableEmail(), new TestNotification());
110+
$channel_response = $this->channel->send(new NotifiableEmail(), new TestNotification());
111+
112+
$this->assertInstanceOf(ResponseInterface::class, $channel_response);
113+
}
114+
115+
/** @test */
116+
public function it_sends_nothing_and_returns_null_when_player_id_empty()
117+
{
118+
$this->oneSignal->shouldReceive('sendNotificationCustom')
119+
->never();
120+
121+
$channel_response = $this->channel->send(new EmptyNotifiable(), new TestNotification());
122+
$this->assertNull($channel_response);
108123
}
109124
}

tests/EmptyNotifiable.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace NotificationChannels\OneSignal\Test;
4+
5+
class EmptyNotifiable
6+
{
7+
use \Illuminate\Notifications\Notifiable;
8+
9+
/**
10+
* @return int
11+
*/
12+
public function routeNotificationForOneSignal()
13+
{
14+
return '';
15+
}
16+
}

0 commit comments

Comments
 (0)