无法模拟对象(Cakephp 3.0.3)

时间:2015-05-25 05:43:50

标签: unit-testing email cakephp mocking cakephp-3.0

我正在使用Cakephp 3.0.3,我的用户实体中有以下方法,

public function sendRecovery()
{
    $email = new Email('default');
    $email->viewVars([
        'userId' => $this->id,
        'token' => $this->token
    ]);
    $email->template('GintonicCMS.forgot_password')
        ->emailFormat('html')
        ->to($this->email)
        ->from([Configure::read('admin_mail') => Configure::read('site_name')])
        ->subject('Forgot Password');
    return $email->send();
}

我正在为它编写testCase。 这是我的testCase方法。

public function testSendRecovery()
{
    $entity = new User([
        'id' => 1,
        'email' => 'hitesh@securemetasys.com',
        'token' => 'jhfkjd456d4sgdsg'
    ]);
    $email = $this->getMock('Cake\Network\Email\Email', ['sendRecovery']);
    $email->expects($this->once())
        ->method('sendRecovery')
        ->with($this->equalTo('hitesh@securemetasys.com'));
    $entity->sendRecovery();
}

当我运行phpunit然后我得到了以下错误,

There was 1 error:

1) GintonicCMS\Test\TestCase\Model\Entity\UserTest::testSendRecovery
InvalidArgumentException: Unknown email configuration "default".

E:\xampp\htdocs\Cake3\Proball-Market\plugins\GintonicCMS\vendor\cakephp\cakephp\src\Network\Email\Email.php:1382
E:\xampp\htdocs\Cake3\Proball-Market\plugins\GintonicCMS\vendor\cakephp\cakephp\src\Network\Email\Email.php:1269
E:\xampp\htdocs\Cake3\Proball-Market\plugins\GintonicCMS\vendor\cakephp\cakephp\src\Network\Email\Email.php:383
E:\xampp\htdocs\Cake3\Proball-Market\plugins\GintonicCMS\src\Model\Entity\User.php:90
E:\xampp\htdocs\Cake3\Proball-Market\plugins\GintonicCMS\tests\TestCase\Model\Entity\UserTest.php:73

任何人都可以帮助我吗?

0 个答案:

没有答案