Last active
August 29, 2015 14:14
-
-
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
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 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; | |
} | |
} |
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
<h1>Hello!</h1> | |
<p>CodeCeption ROX!!</p> |
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 | |
Route::get('mail', function(){ | |
\Mail::queue('emails.hello', [], function($message) use($email){ | |
$message->to($email)->subject('Email Test!'); | |
}); | |
}); |
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
$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