Completed
Push — master ( 20b8ce...b87dd6 )
by Alexey
05:19
created

ContactFormTest::testSendEmail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.2
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
3
namespace frontend\tests\unit\models;
4
5
use Yii;
6
use modules\main\models\frontend\ContactForm;
7
8
/**
9
 * Class ContactFormTest
10
 * @package frontend\tests\unit\models
11
 */
12
class ContactFormTest extends \Codeception\Test\Unit
13
{
14
    /**
15
     * @inheritdoc
16
     */
17
    public function testSendEmail()
18
    {
19
        $model = new ContactForm();
20
21
        $model->attributes = [
22
            'name' => 'Tester',
23
            'email' => '[email protected]',
24
            'subject' => 'very important letter subject',
25
            'body' => 'body of current message',
26
        ];
27
28
        expect_that($model->sendEmail('[email protected]'));
29
30
        // using Yii2 module actions to check email was sent
31
        $this->tester->seeEmailIsSent();
0 ignored issues
show
Bug Best Practice introduced by
The property tester does not exist on frontend\tests\unit\models\ContactFormTest. Did you maybe forget to declare it?
Loading history...
32
33
        $emailMessage = $this->tester->grabLastSentEmail();
34
        expect('valid email is sent', $emailMessage)->isInstanceOf('yii\mail\MessageInterface');
35
        expect($emailMessage->getTo())->hasKey('[email protected]');
36
        expect($emailMessage->getFrom())->hasKey('[email protected]');
37
        expect($emailMessage->getSubject())->equals('very important letter subject');
38
        expect($emailMessage->toString())->contains('body of current message');
39
    }
40
}
41