Skip to content

Commit 7844e80

Browse files
committed
add channel test
1 parent 88a3412 commit 7844e80

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

tests/ChannelTest.php

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22

33
namespace NotificationChannels\PusherPushNotifications\Test;
44

5-
use Mockery;
5+
use Illuminate\Notifications\Notifiable;
66
use NotificationChannels\PusherPushNotifications\PusherChannel;
7+
use Illuminate\Notifications\Notification;
8+
use NotificationChannels\PusherPushNotifications\PusherMessage;
79
use PHPUnit_Framework_TestCase;
10+
use Mockery;
811
use Pusher;
912

1013
class ChannelTest extends PHPUnit_Framework_TestCase
1114
{
12-
/** @var Mockery\Mock */
13-
protected $pusher;
14-
15-
/** @var \NotificationChannels\PusherPushNotifications\PusherChannel */
16-
protected $channel;
17-
1815
public function setUp()
1916
{
2017
$this->pusher = Mockery::mock(Pusher::class);
2118

2219
$this->channel = new PusherChannel($this->pusher);
20+
21+
$this->notification = new TestNotification;
22+
23+
$this->notifiable = new TestNotifiable;
2324
}
2425

2526
public function tearDown()
@@ -32,10 +33,30 @@ public function tearDown()
3233
/** @test */
3334
public function it_can_send_a_notification()
3435
{
35-
/* TODO: revisit this test after L5.3 comes out */
36+
$message = $this->notification->toPushNotification($this->notifiable);
37+
38+
$data = $message->toArray();
39+
40+
$this->pusher->shouldReceive('notify')->with('interest_name', $data, true)->andReturn(['status' => 202]);
41+
42+
$this->channel->send($this->notifiable, $this->notification);
43+
}
44+
}
3645

37-
//$this->pusher->shouldReceive('notify')->once()->andReturn(['response' => 200]);
46+
class TestNotifiable
47+
{
48+
use Notifiable;
3849

39-
//$this->channel->send(new Notifiable(), new Notification());
50+
public function routeNotificationForPusherPushNotifications()
51+
{
52+
return 'interest_name';
53+
}
54+
}
55+
56+
class TestNotification extends Notification
57+
{
58+
public function toPushNotification($notifiable)
59+
{
60+
return new PusherMessage();
4061
}
4162
}

tests/MessageTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function it_provides_a_create_method()
3939
public function by_default_it_will_send_a_message_to_ios()
4040
{
4141
$this->assertTrue(Arr::has($this->message->toArray(), 'apns'));
42+
$this->assertFalse(Arr::has($this->message->toArray(), 'gcm'));
4243
}
4344

4445
/** @test */
@@ -47,10 +48,12 @@ public function it_can_send_a_message_to_the_right_platform()
4748
$this->message->ios();
4849

4950
$this->assertTrue(Arr::has($this->message->toArray(), 'apns'));
51+
$this->assertFalse(Arr::has($this->message->toArray(), 'gcm'));
5052

5153
$this->message->android();
5254

5355
$this->assertTrue(Arr::has($this->message->toArray(), 'gcm'));
56+
$this->assertFalse(Arr::has($this->message->toArray(), 'apns'));
5457
}
5558

5659
/** @test */
@@ -112,4 +115,13 @@ public function it_will_throw_an_exception_when_an_unsupported_platform_is_used(
112115

113116
$this->message->platform('bla bla');
114117
}
118+
119+
/** @test */
120+
public function it_can_send_message_to_multiple_platforms()
121+
{
122+
$this->message->ios()->withAndroid(new PusherMessage());
123+
124+
$this->assertTrue(Arr::has($this->message->toArray(), 'apns'));
125+
$this->assertTrue(Arr::has($this->message->toArray(), 'gcm'));
126+
}
115127
}

0 commit comments

Comments
 (0)