【发布时间】:2016-12-07 19:56:50
【问题描述】:
我想用 phpunit 和 cakephp 3.x 制作测试用例,shell 发送电子邮件。这是我在 shell 中的功能:
class CompaniesShellTest extends TestCase
{
public function monthlySubscription()
{
/* .... */
$email = new Email('staff');
try {
$email->template('Companies.alert_renew_success', 'base')
->theme('Backend')
->emailFormat('html')
->profile(['ElasticMail' => ['channel' => ['alert_renew_success']]])
->to($user->username)
//->to('dario@example.com')
->subject('Eseguito rinnovo mensile abbonamento')
->viewVars(['company' => $company, 'user' => $user])
->send();
} catch (Exception $e) {
debug($e);
}
/* ... */
}
}
在我的测试课中我有这个功能
/**
* setUp method
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
$this->CompaniesShell = new CompaniesShell($this->io);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown()
{
unset($this->CompaniesShell);
parent::tearDown();
}
/**
* Test monthlySubscription method
*
* @return void
*/
public function testMonthlySubscription()
{
$email = $this->getMock('Cake\Mailer\Email', array('subject', 'from', 'to', 'send'));
$email->expects($this->exactly(3))->method('send')->will($this->returnValue(true));
$this->CompaniesShell->MonthlySubscription();
}
但这不起作用。 有任何想法吗?我想检查邮件是否成功发送以及发送了多少次。
【问题讨论】:
标签: shell cakephp phpunit cakephp-3.0