-
-
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.
- Loading branch information
Showing
7 changed files
with
170 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php namespace Orchestra\Notifier; | ||
|
||
use Illuminate\Mail\Mailer as IlluminateMailer; | ||
use Illuminate\Auth\Reminders\RemindableInterface; | ||
|
||
class LaravelNotifier implements NotifierInterface | ||
{ | ||
/** | ||
* Mailer instance. | ||
* | ||
* @var \Illuminate\Mail\Mailer | ||
*/ | ||
protected $mailer; | ||
|
||
/** | ||
* Setup Illuminate Mailer. | ||
* | ||
* @param \Illuminate\Mail\Mailer $mailer | ||
*/ | ||
public function __construct(IlluminateMailer $mailer) | ||
{ | ||
$this->mailer = $mailer; | ||
} | ||
|
||
/** | ||
* Send notification via API. | ||
* | ||
* @param \Illuminate\Auth\Reminders\RemindableInterface $user | ||
* @param string $subject | ||
* @param string|array $view | ||
* @param array $data | ||
* @return boolean | ||
*/ | ||
public function send(RemindableInterface $user, $subject, $view, array $data = array()) | ||
{ | ||
$sent = $this->mailer->send($view, $data, function ($mail) use ($user, $subject) { | ||
$mail->to($user->getReminderEmail()); | ||
$mail->subject($subject); | ||
}); | ||
|
||
return (count($sent) > 0); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?php | ||
|
||
return array( | ||
'default' => 'orchestra', | ||
'default' => 'laravel', | ||
); |
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,74 @@ | ||
<?php namespace Orchestra\Notifier\TestCase; | ||
|
||
use Mockery as m; | ||
use Orchestra\Notifier\LaravelNotifier; | ||
|
||
class LaravelNotifierTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* Teardown the test environment. | ||
*/ | ||
public function tearDown() | ||
{ | ||
m::close(); | ||
} | ||
|
||
/** | ||
* Test Orchestra\Notifier\LaravelNotifier::send() method without | ||
* queue. | ||
* | ||
* @test | ||
*/ | ||
public function testSendMethodSucceed() | ||
{ | ||
$mailer = m::mock('\Illuminate\Mail\Mailer'); | ||
$user = m::mock('\Illuminate\Auth\Reminders\RemindableInterface'); | ||
$subject = 'foobar'; | ||
$view = 'foo.bar'; | ||
$data = array(); | ||
|
||
$user->shouldReceive('getReminderEmail')->once()->andReturn('hello@orchestraplatform.com'); | ||
|
||
$mailer->shouldReceive('send')->once()->with($view, $data, m::type('Closure')) | ||
->andReturnUsing(function ($v, $d, $c) use ($mailer) { | ||
$c($mailer); | ||
|
||
return array('hello@orchestraplatform.com'); | ||
}) | ||
->shouldReceive('to')->once()->with('hello@orchestraplatform.com')->andReturnNull() | ||
->shouldReceive('subject')->once()->with($subject)->andReturnNull(); | ||
|
||
$stub = new LaravelNotifier($mailer); | ||
|
||
$this->assertTrue($stub->send($user, $subject, $view, $data)); | ||
} | ||
|
||
/** | ||
* Test Orchestra\Notifier\LaravelNotifier::send() method failed. | ||
* | ||
* @test | ||
*/ | ||
public function testSendMethodFailed() | ||
{ | ||
$mailer = m::mock('\Illuminate\Mail\Mailer'); | ||
$user = m::mock('\Illuminate\Auth\Reminders\RemindableInterface'); | ||
$subject = 'foobar'; | ||
$view = 'foo.bar'; | ||
$data = array(); | ||
|
||
$user->shouldReceive('getReminderEmail')->once()->andReturn('hello@orchestraplatform.com'); | ||
|
||
$mailer->shouldReceive('send')->once()->with($view, $data, m::type('Closure')) | ||
->andReturnUsing(function ($v, $d, $c) use ($mailer) { | ||
$c($mailer); | ||
|
||
return array(); | ||
}) | ||
->shouldReceive('to')->once()->with('hello@orchestraplatform.com')->andReturnNull() | ||
->shouldReceive('subject')->once()->with($subject)->andReturnNull(); | ||
|
||
$stub = new LaravelNotifier($mailer); | ||
|
||
$this->assertFalse($stub->send($user, $subject, $view, $data)); | ||
} | ||
} |
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