-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Mane-Olawale/development
[ADDITION: Tests] Added channel tests and test entities
- Loading branch information
Showing
10 changed files
with
255 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
|
||
namespace ManeOlawale\Laravel\Termii\Tests\Channel; | ||
|
||
use Mockery as Mock; | ||
use ManeOlawale\Laravel\Termii\Tests\TestCase; | ||
use ManeOlawale\Laravel\Termii\Tests\Entities\TermiiTestNotification; | ||
use ManeOlawale\Laravel\Termii\Tests\Entities\TermiiTestNotificationWithCustomClient; | ||
use ManeOlawale\Laravel\Termii\Tests\Entities\TermiiTestNotificationWithCustomClientAndFrom; | ||
use ManeOlawale\Laravel\Termii\Tests\Entities\TermiiTestNotificationWithCustomFrom; | ||
use ManeOlawale\Laravel\Termii\Tests\Entities\TermiiTestNotifiable; | ||
use ManeOlawale\Laravel\Termii\Channels\TermiiSmsChannel; | ||
use ManeOlawale\Termii\Client; | ||
use ManeOlawale\Termii\Api\Sms; | ||
|
||
class TermiiChannelTest extends TestCase | ||
{ | ||
public function test_sms_is_sent_via_termii() | ||
{ | ||
$notification = new TermiiTestNotification; | ||
$notifiable = new TermiiTestNotifiable; | ||
|
||
|
||
$channel = new TermiiSmsChannel( | ||
$termii = Mock::mock(Client::class), 'Olawale' | ||
); | ||
|
||
$sms = Mock::mock(Sms::class); | ||
|
||
$sms->shouldReceive('send') | ||
->with( | ||
$notifiable->phone, 'Hello world', 'Olawale', NULL | ||
) | ||
->once(); | ||
|
||
$termii->shouldReceive('api') | ||
->with( | ||
'sms' | ||
) | ||
->once() | ||
->andReturn($sms); | ||
|
||
$channel->send($notifiable, $notification); | ||
} | ||
|
||
public function test_sms_is_sent_via_custom_client() | ||
{ | ||
|
||
$customClient = Mock::mock(Client::class); | ||
|
||
$sms = Mock::mock(Sms::class); | ||
|
||
$notification = new TermiiTestNotificationWithCustomClient($customClient); | ||
$notifiable = new TermiiTestNotifiable; | ||
|
||
$sms->shouldReceive('send') | ||
->with( | ||
$notifiable->phone, 'Hello world', 'Olawale', NULL | ||
) | ||
->once(); | ||
|
||
$customClient->shouldReceive('api') | ||
->with( | ||
'sms' | ||
) | ||
->once() | ||
->andReturn($sms); | ||
|
||
$channel = new TermiiSmsChannel( | ||
Mock::mock(Client::class), 'Olawale' | ||
); | ||
|
||
$channel->send($notifiable, $notification); | ||
} | ||
|
||
public function test_sms_is_sent_via_custom_from() | ||
{ | ||
$notification = new TermiiTestNotificationWithCustomFrom; | ||
$notifiable = new TermiiTestNotifiable; | ||
|
||
|
||
$channel = new TermiiSmsChannel( | ||
$termii = Mock::mock(Client::class), 'Olawale' | ||
); | ||
|
||
$sms = Mock::mock(Sms::class); | ||
|
||
$sms->shouldReceive('send') | ||
->with( | ||
$notifiable->phone, 'Hello world', 'Adedotun', NULL | ||
) | ||
->once(); | ||
|
||
$termii->shouldReceive('api') | ||
->with( | ||
'sms' | ||
) | ||
->once() | ||
->andReturn($sms); | ||
|
||
$channel->send($notifiable, $notification); | ||
} | ||
|
||
public function test_sms_is_sent_via_custom_from_and_client() | ||
{ | ||
|
||
$customClient = Mock::mock(Client::class); | ||
|
||
$sms = Mock::mock(Sms::class); | ||
|
||
$notification = new TermiiTestNotificationWithCustomClientAndFrom( | ||
$customClient | ||
); | ||
$notifiable = new TermiiTestNotifiable; | ||
|
||
$sms->shouldReceive('send') | ||
->with( | ||
$notifiable->phone, 'Hello world', 'Adedotun', NULL | ||
) | ||
->once(); | ||
|
||
$customClient->shouldReceive('api') | ||
->with( | ||
'sms' | ||
) | ||
->once() | ||
->andReturn($sms); | ||
|
||
$channel = new TermiiSmsChannel( | ||
Mock::mock(Client::class), 'Olawale' | ||
); | ||
|
||
$channel->send($notifiable, $notification); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace ManeOlawale\Laravel\Termii\Tests\Entities; | ||
|
||
use Illuminate\Notifications\Notifiable; | ||
|
||
class TermiiTestNotifiable | ||
{ | ||
use Notifiable; | ||
|
||
public $phone = '5555555555'; | ||
|
||
public function routeNotificationForTermii($notification) | ||
{ | ||
return $this->phone; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace ManeOlawale\Laravel\Termii\Tests\Entities; | ||
|
||
use Illuminate\Notifications\Notification; | ||
use ManeOlawale\Laravel\Termii\Messages\TermiiMessage; | ||
|
||
class TermiiTestNotification extends Notification | ||
{ | ||
public function toTermii($notifiable) | ||
{ | ||
return new TermiiMessage('Hello world'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace ManeOlawale\Laravel\Termii\Tests\Entities; | ||
|
||
use ManeOlawale\Termii\Client; | ||
use Illuminate\Notifications\Notification; | ||
use ManeOlawale\Laravel\Termii\Messages\TermiiMessage; | ||
|
||
class TermiiTestNotificationWithCustomClient extends Notification | ||
{ | ||
public $client; | ||
|
||
public function __construct(Client $client) { | ||
$this->client = $client; | ||
} | ||
|
||
|
||
public function toTermii($notifiable) | ||
{ | ||
return (new TermiiMessage('Hello world'))->client($this->client); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/Entities/TermiiTestNotificationWithCustomClientAndFrom.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace ManeOlawale\Laravel\Termii\Tests\Entities; | ||
|
||
use ManeOlawale\Termii\Client; | ||
use Illuminate\Notifications\Notification; | ||
use ManeOlawale\Laravel\Termii\Messages\TermiiMessage; | ||
|
||
class TermiiTestNotificationWithCustomClientAndFrom extends Notification | ||
{ | ||
public $client; | ||
|
||
public function __construct(Client $client) { | ||
$this->client = $client; | ||
} | ||
|
||
|
||
public function toTermii($notifiable) | ||
{ | ||
return (new TermiiMessage('Hello world'))->client($this->client)->from('Adedotun'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace ManeOlawale\Laravel\Termii\Tests\Entities; | ||
|
||
use ManeOlawale\Termii\Client; | ||
use Illuminate\Notifications\Notification; | ||
use ManeOlawale\Laravel\Termii\Messages\TermiiMessage; | ||
|
||
class TermiiTestNotificationWithCustomFrom extends Notification | ||
{ | ||
|
||
public function toTermii($notifiable) | ||
{ | ||
return (new TermiiMessage('Hello world'))->from('Adedotun'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace ManeOlawale\Laravel\Termii\Tests; | ||
|
||
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; | ||
use PHPUnit\Framework\TestCase as BaseTestCase; | ||
|
||
class TestCase extends BaseTestCase | ||
{ | ||
use MockeryPHPUnitIntegration; | ||
} |