Passed
Pull Request — master (#305)
by Wilmer
03:32
created

ContactFormTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 18
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testEmailIsSentOnContact() 0 25 1
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;
0 ignored issues
show
Bug introduced by
The type UnitTester was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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