Passed
Pull Request — master (#305)
by Wilmer
14:19
created

ContactFormTest::testEmailIsSentOnContact()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 25
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace tests\unit\models;
6
7
use app\models\ContactForm;
8
use yii\mail\MessageInterface;
9
10
final class ContactFormTest extends \Codeception\Test\Unit
11
{
12
    public \UnitTester $tester;
13
14
    public function testEmailIsSentOnContact(): void
15
    {
16
        $model = new ContactForm();
17
18
        $model->attributes = [
19
            'name' => 'Tester',
20
            'email' => '[email protected]',
21
            'subject' => 'very important letter subject',
22
            'body' => 'body of current message',
23
            'verifyCode' => 'testme',
24
        ];
25
26
        verify($model->contact('[email protected]'))->notEmpty();
27
28
        // using Yii2 module actions to check email was sent
29
        $this->tester->seeEmailIsSent();
30
31
        /** @var MessageInterface $emailMessage */
32
        $emailMessage = $this->tester->grabLastSentEmail();
33
        verify($emailMessage)->instanceOf('yii\mail\MessageInterface');
34
        verify($emailMessage->getTo())->arrayHasKey('[email protected]');
35
        verify($emailMessage->getFrom())->arrayHasKey('[email protected]');
36
        verify($emailMessage->getReplyTo())->arrayHasKey('[email protected]');
37
        verify($emailMessage->getSubject())->equals('very important letter subject');
38
        verify($emailMessage->toString())->stringContainsString('body of current message');
39
    }
40
}
41