Fixed contact form tests

This commit is contained in:
Alexander Makarov 2019-04-23 15:31:43 +03:00
parent e38c34a935
commit 3076318d05
No known key found for this signature in database
GPG Key ID: 3617B79C6A325E4A

View File

@ -2,6 +2,9 @@
namespace tests\unit\models;
use app\models\ContactForm;
use yii\mail\MessageInterface;
class ContactFormTest extends \Codeception\Test\Unit
{
private $model;
@ -19,7 +22,7 @@ class ContactFormTest extends \Codeception\Test\Unit
$this->model->expects($this->once())
->method('validate')
->will($this->returnValue(true));
->willReturn(true);
$this->model->attributes = [
'name' => 'Tester',
@ -33,10 +36,12 @@ class ContactFormTest extends \Codeception\Test\Unit
// using Yii2 module actions to check email was sent
$this->tester->seeEmailIsSent();
/** @var MessageInterface $emailMessage */
$emailMessage = $this->tester->grabLastSentEmail();
expect('valid email is sent', $emailMessage)->isInstanceOf('yii\mail\MessageInterface');
expect($emailMessage->getTo())->hasKey('admin@example.com');
expect($emailMessage->getFrom())->hasKey('tester@example.com');
expect($emailMessage->getFrom())->hasKey('noreply@example.com');
expect($emailMessage->getReplyTo())->hasKey('tester@example.com');
expect($emailMessage->getSubject())->equals('very important letter subject');
expect($emailMessage->toString())->contains('body of current message');
}