Skip to content

Commit

Permalink
Test events are dispatched
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrilMazur committed Apr 10, 2017
1 parent ceab3cc commit 7cf5d6d
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tests/Mail/MailMailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,25 @@ public function testFailedRecipientsAreAppendedAndCanBeRetrieved()
$this->assertEquals(['taylorotwell@gmail.com'], $mailer->failures());
}

protected function getMailer()
public function testEventsAreDispatched()
{
return new \Illuminate\Mail\Mailer(m::mock('Illuminate\Contracts\View\Factory'), m::mock('Swift_Mailer'));
unset($_SERVER['__mailer.test']);
$events = m::mock('Illuminate\Contracts\Events\Dispatcher');
$events->shouldReceive('until')->once()->with(m::type('Illuminate\Mail\Events\MessageSending'));
$events->shouldReceive('dispatch')->once()->with(m::type('Illuminate\Mail\Events\MessageSent'));
$mailer = $this->getMailer($events);
$view = m::mock('StdClass');
$mailer->getViewFactory()->shouldReceive('make')->once()->andReturn($view);
$view->shouldReceive('render')->once()->andReturn('rendered.view');
$this->setSwiftMailer($mailer);
$mailer->getSwiftMailer()->shouldReceive('send')->once()->with(m::type('Swift_Message'), []);
$mailer->send('foo', ['data'], function ($m) {
});
}

protected function getMailer($events = null)
{
return new \Illuminate\Mail\Mailer(m::mock('Illuminate\Contracts\View\Factory'), m::mock('Swift_Mailer'), $events);
}

public function setSwiftMailer($mailer)
Expand Down

0 comments on commit 7cf5d6d

Please sign in to comment.