Skip to content

Commit

Permalink
Merge branch '2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
crynobone committed Dec 28, 2013
2 parents 0ee20ac + 7f09b73 commit a6e8a0b
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 8 deletions.
43 changes: 43 additions & 0 deletions src/Orchestra/Notifier/LaravelNotifier.php
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);
}
}
2 changes: 1 addition & 1 deletion src/Orchestra/Notifier/NotifierInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface NotifierInterface
*
* @param \Illuminate\Auth\Reminders\RemindableInterface $user
* @param string $subject
* @param string $view
* @param string|array $view
* @param array $data
* @return boolean
*/
Expand Down
12 changes: 11 additions & 1 deletion src/Orchestra/Notifier/NotifierManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

class NotifierManager extends Manager
{
/**
* Create Laravel driver.
*
* @return OrchestraNotifier
*/
protected function createLaravelDriver()
{
return new LaravelNotifier($this->app['mailer']);
}

/**
* Create Orchestra Platform driver.
*
Expand All @@ -24,6 +34,6 @@ protected function createOrchestraDriver()
*/
public function getDefaultDriver()
{
return $this->app['config']->get('orchestra/notifier::driver', 'orchestra');
return $this->app['config']->get('orchestra/notifier::driver', 'laravel');
}
}
2 changes: 1 addition & 1 deletion src/Orchestra/Notifier/OrchestraNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(Mailer $mailer)
*
* @param \Illuminate\Auth\Reminders\RemindableInterface $user
* @param string $subject
* @param string $view
* @param string|array $view
* @param array $data
* @return boolean
*/
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

return array(
'default' => 'orchestra',
'default' => 'laravel',
);
74 changes: 74 additions & 0 deletions tests/LaravelNotifierTest.php
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));
}
}
43 changes: 39 additions & 4 deletions tests/NotifierManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ public function tearDown()
m::close();
}

/**
* Test Orchestra\Notifier\NotifierManager::createDefaultDriver()
* method.
*
* @test
*/
public function testCreateDefaultDriverMethod()
{
$app = new Container;

$app['config'] = $config = m::mock('\Illuminate\Config\Repository');
$app['mailer'] = $mailer = m::mock('\Illuminate\Mail\Mailer');

$config->shouldReceive('get')->once()
->with('orchestra/notifier::driver', 'laravel')->andReturn('laravel');

$stub = new NotifierManager($app);

$this->assertInstanceOf('\Orchestra\Notifier\LaravelNotifier', $stub->driver());
}

/**
* Test Orchestra\Notifier\NotifierManager::createOrchestraDriver()
* method.
Expand All @@ -24,16 +45,30 @@ public function testCreateOrchestraDriverMethod()
{
$app = new Container;

$app['config'] = $config = m::mock('\Illuminate\Config\Repository');
$app['orchestra.mail'] = $mailer = m::mock('\Orchestra\Notifier\Mailer');
$app['orchestra.memory'] = $memory = m::mock('\Orchestra\Memory\Drivers\Driver');

$config->shouldReceive('get')->once()
->with('orchestra/notifier::driver', 'orchestra')->andReturn('orchestra');
$memory->shouldReceive('makeOrFallback')->once()->andReturn($memory);

$stub = new NotifierManager($app);

$this->assertInstanceOf('\Orchestra\Notifier\OrchestraNotifier', $stub->driver());
$this->assertInstanceOf('\Orchestra\Notifier\OrchestraNotifier', $stub->driver('orchestra'));
}

/**
* Test Orchestra\Notifier\NotifierManager::createLaravelDriver()
* method.
*
* @test
*/
public function testCreateLaravelDriverMethod()
{
$app = new Container;

$app['mailer'] = $mailer = m::mock('\Illuminate\Mail\Mailer');

$stub = new NotifierManager($app);

$this->assertInstanceOf('\Orchestra\Notifier\LaravelNotifier', $stub->driver('laravel'));
}
}

0 comments on commit a6e8a0b

Please sign in to comment.