Skip to content

Instantly share code, notes, and snippets.

@Rokt33r
Last active August 29, 2015 14:14
Show Gist options
  • Save Rokt33r/f20548e3841151435794 to your computer and use it in GitHub Desktop.
Save Rokt33r/f20548e3841151435794 to your computer and use it in GitHub Desktop.
CodeceptionでのMockを使ったFacadeのテスト / Using Mock to test Facade with Codeception for Laravel ref: http://qiita.com/fluke8259/items/98e6b2d82f214fc91230
<?php namespace Codeception\Module;
class FunctionalHelper extends \Codeception\Module
{
public function getApp(){
return $app = $this->getModule('Laravel4')->kernel;
}
public function readyMailerMock(){
$mock = \Mockery::mock('Mailer');
$this->getApp()['mailer'] = $mock;
return $mock;
}
public function seeMailQueued($view, $email){
$mock = $this->readyMailerMock();
$mock->shouldReceive('queue')->once()->with($view, \Mockery::any(), \Mockery::on(function($closure)use($email){
$message = \Mockery::mock('Message');
$message->shouldReceive('to')->with($email)->andReturn(\Mockery::self());
$message->shouldReceive('subject')->with(\Mockery::any())->andReturn(\Mockery::self());
$closure($message);
return true;
}));
return $mock;
}
}
<h1>Hello!</h1>
<p>CodeCeption ROX!!</p>
<?php
Route::get('mail', function(){
\Mail::queue('emails.hello', [], function($message) use($email){
$message->to($email)->subject('Email Test!');
});
});
$I->wantTo('send a mail');
$email = '[email protected]';
$I->seeMailQueued('emails.hello', $email);
$I->amOnPage('mail');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment