for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace frontend\tests\unit\models;
use Yii;
use modules\main\models\frontend\ContactForm;
/**
* Class ContactFormTest
* @package frontend\tests\unit\models
*/
class ContactFormTest extends \Codeception\Test\Unit
{
* @inheritdoc
public function testSendEmail()
$model = new ContactForm();
$model->attributes = [
'name' => 'Tester',
'email' => '[email protected]',
'subject' => 'very important letter subject',
'body' => 'body of current message',
];
expect_that($model->sendEmail('[email protected]'));
// using Yii2 module actions to check email was sent
$this->tester->seeEmailIsSent();
tester
frontend\tests\unit\models\ContactFormTest
$emailMessage = $this->tester->grabLastSentEmail();
expect('valid email is sent', $emailMessage)->isInstanceOf('yii\mail\MessageInterface');
expect($emailMessage->getTo())->hasKey('[email protected]');
expect($emailMessage->getFrom())->hasKey('[email protected]');
expect($emailMessage->getSubject())->equals('very important letter subject');
expect($emailMessage->toString())->contains('body of current message');
}