Created
November 1, 2014 07:15
-
-
Save cod3beat/75b7cda23ea50c6d8901 to your computer and use it in GitHub Desktop.
Mocking Mail di Laravel menggunakan Phake: Memastikan bahwa email dikirim
This file contains hidden or 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
<?php | |
use Phake as p; | |
class MockingMailTest extends \TestCase | |
{ | |
function test_it_should_send_mail() | |
{ | |
// Mocking Laravel Mail | |
$mockedMail = p::mock('Illuminate\Mail\Mailer'); | |
$this->app->instance('mailer', $mockedMail); | |
// Lakukan proses tertentu | |
// Di dalam proses ini, aplikasi seharusnya mengirim email menggunakan Mail | |
// Memastikan bahwa email dikirim menggunakan: | |
// Template email.suatuTemplate | |
// Dengan template konent berupa ['content'=>'Suatu Konten'] | |
p::verify($mockedMail, p::times(1))->send('email.suatuTemplate', ['content'=>'Suatu Konten'], $this->isInstanceOf('Closure')); | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace Suatu\Namespace; | |
class SuatuProsesYangMengirimMail | |
{ | |
public function send($receiverEmail, $receiverName, $content, $template) | |
{ | |
\Mail::send($template, $content, function($message) use ($receiverEmail, $receiverName) { | |
// proses mengirimm mail | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment