dimanche 24 mai 2015

Fail to mock object (Cakephp 3.0.3)

I am using Cakephp 3.0.3 and I have following method in my User Entity,

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();
}

i am writing testCase for it. here is my testCase Method.

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();
}

when i run phpunit then i got following error,

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

can any one help me Please?

Aucun commentaire:

Enregistrer un commentaire