Skip to content

Commit

Permalink
Test with custom client provided
Browse files Browse the repository at this point in the history
  • Loading branch information
dwightwatson committed Feb 23, 2020
1 parent 8e9c891 commit 6dc77bc
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions tests/ApnChannelTest.php
Expand Up @@ -19,19 +19,28 @@ public function setUp(): void
{
$this->client = Mockery::mock(Client::class);
$this->channel = new ApnChannel($this->client);
$this->notification = new TestNotification;
$this->notifiable = new TestNotifiable;
}

/** @test */
public function it_can_send_a_notification()
{
$message = $this->notification->toApn($this->notifiable);

$this->client->shouldReceive('addNotification');
$this->client->shouldReceive('push')->once();

$this->channel->send($this->notifiable, $this->notification);
$this->channel->send(new TestNotifiable, new TestNotification);
}

/** @test */
public function it_can_send_a_notification_with_custom_client()
{
$customClient = Mockery::mock(Client::class);

$this->client->shouldNotReceive('addNotification');

$customClient->shouldReceive('addNotification');
$customClient->shouldReceive('push')->once();

$this->channel->send(new TestNotifiable, (new TestNotificationWithClient($customClient)));
}
}

Expand All @@ -58,3 +67,18 @@ public function toApn($notifiable)
return new ApnMessage('title');
}
}

class TestNotificationWithClient extends Notification
{
protected $client;

public function __construct($client)
{
$this->client = $client;
}

public function toApn($notifiable)
{
return (new ApnMessage('title'))->via($this->client);
}
}

0 comments on commit 6dc77bc

Please sign in to comment.