Passed
Pull Request — master (#305)
by Wilmer
03:39
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 UnitTester;
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...
9
use yii\mail\MessageInterface;
10
11
final class ContactFormTest extends \Codeception\Test\Unit
12
{
13
    public UnitTester $tester;
14
15
    public function testEmailIsSentOnContact(): void
16
    {
17
        $model = new ContactForm();
18
19
        $model->attributes = [
20
            'name' => 'Tester',
21
            'email' => '[email protected]',
22
            'subject' => 'very important letter subject',
23
            'body' => 'body of current message',
24
            'verifyCode' => 'testme',
25
        ];
26
27
        verify($model->contact('[email protected]'))->notEmpty();
28
29
        // using Yii2 module actions to check email was sent
30
        $this->tester->seeEmailIsSent();
31
32
        /** @var MessageInterface $emailMessage */
33
        $emailMessage = $this->tester->grabLastSentEmail();
34
        verify($emailMessage)->instanceOf('yii\mail\MessageInterface');
35
        verify($emailMessage->getTo())->arrayHasKey('[email protected]');
36
        verify($emailMessage->getFrom())->arrayHasKey('[email protected]');
37
        verify($emailMessage->getReplyTo())->arrayHasKey('[email protected]');
38
        verify($emailMessage->getSubject())->equals('very important letter subject');
39
        verify($emailMessage->toString())->stringContainsString('body of current message');
40
    }
41
}
42