RecordTraitTest::test_buildMailMessageBody()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 7
c 1
b 1
f 0
nc 1
nop 0
dl 0
loc 12
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nip\Mail\Tests\Models\Mailable;
6
7
use Mockery\Mock;
8
use Nip\Mail\Tests\AbstractTest;
9
use Nip\Mail\Tests\Fixtures\Models\Emails\Email;
10
11
/**
12
 * Class RecordTraitTest.
13
 */
14
class RecordTraitTest extends AbstractTest
15
{
16
    public function testBuildMailMessageMergeTagsStripNotPresent()
17
    {
18
        $email = new Email();
19
        $email->setBody('{{var1}}{{var3}}');
20
        $email->setMergeTags(['var1' => 1, 'var2' => 2, 'var3' => 3]);
21
22
        $message = $email->newMailMessage();
23
        $email->buildMailMessageMergeTags($message);
24
25
        $tags = $message->getMergeTags();
26
        self::assertCount(2, $tags);
27
    }
28
29
    public function test_body_get_setters()
30
    {
31
        $email = new Email();
32
        $email->writeData([
33
            'body' => '{{var1}}{{var2}}',
34
            'merge_tags' => [
35
                'var1' => 1,
36
                'var2' => 2,
37
            ],
38
        ]);
39
40
        self::assertSame('{{var1}}{{var2}}', $email->getBody());
41
    }
42
43
    public function test_buildMailMessageRecipients()
44
    {
45
        /** @var Mock|Email $email */
46
        $email = \Mockery::mock(Email::class)->shouldAllowMockingProtectedMethods()->makePartial();
47
        $email->writeData([
0 ignored issues
show
Bug introduced by
The method writeData() does not exist on Mockery\Mock. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
        $email->/** @scrutinizer ignore-call */ 
48
                writeData([

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
48
            'to' => '[email protected], [email protected]',
49
        ]);
50
        $email->bcc = [
0 ignored issues
show
Bug introduced by
The property bcc does not seem to exist on Mockery\Mock.
Loading history...
51
            '[email protected]' => 'Test 1',
52
            '[email protected]' => 'Test 2',
53
        ];
54
55
        $message = $email->newMailMessage();
0 ignored issues
show
Bug introduced by
The method newMailMessage() does not exist on Mockery\Mock. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
        /** @scrutinizer ignore-call */ 
56
        $message = $email->newMailMessage();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
56
        $email->buildMailMessageRecipients($message);
0 ignored issues
show
Bug introduced by
The method buildMailMessageRecipients() does not exist on Mockery\Mock. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
        $email->/** @scrutinizer ignore-call */ 
57
                buildMailMessageRecipients($message);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
57
58
        $tos = $message->getTo();
59
        self::assertCount(2, $tos);
60
        self::assertSame('[email protected]', $tos[1]->getAddress());
61
    }
62
63
    public function test_buildMailMessageBody()
64
    {
65
        $email = new Email();
66
        $email->setBody('{{var1}}{{var2}}');
67
68
        $message = $email->newMailMessage();
69
        $message->addFrom('[email protected]');
70
        $message->addTo('[email protected]');
71
72
        $email->buildMailMessageBody($message);
73
74
        self::assertStringContainsString('{{var1}}{{var2}}', (string) $message->getBody()->toString());
75
    }
76
}
77