0
我想用phpunit和cakephp 3.x來製作測試用例,發送郵件的shell。這是我的功能分爲殼:從Shell CakePHP 3.x測試電子郵件
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('[email protected]')
->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();
}
但是,這是行不通的。 任何想法?我想檢查郵件是否成功發送以及發送多少次。