Completed
Push — master ( 80ef2e...65d1c9 )
by
unknown
58:18 queued 18:37
created

TwigFileRepositoryTest::testSubject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace SfCod\EmailEngineBundle\Tests\Repository;
4
5
use PHPUnit\Framework\TestCase;
6
use SfCod\EmailEngineBundle\Example\TestEmailOptions;
7
use SfCod\EmailEngineBundle\Example\TestEmailTemplate;
8
use SfCod\EmailEngineBundle\Repository\TwigFileRepository;
9
10
/**
11
 * Class TwigFileRepositoryTest
12
 *
13
 * @author Virchenko Maksim <[email protected]>
14
 *
15
 * @package SfCod\EmailEngineBundle\Tests\Repository
16
 */
17
class TwigFileRepositoryTest extends TestCase
18
{
19
    /**
20
     * Test get subject
21
     *
22
     * @throws \ReflectionException
23
     * @throws \SfCod\EmailEngineBundle\Exception\RepositoryUnavailableException
24
     * @throws \Throwable
25
     */
26
    public function testSubject()
27
    {
28
        $text = uniqid('subject_');
29
30
        $repository = $this->mockRepository();
31
32
        $subject = $repository->getSubjectTemplate([
33
            'subject' => $text,
34
        ]);
35
36
        $this->assertEquals($text, $subject);
37
    }
38
39
    /**
40
     * Test get body
41
     *
42
     * @throws \ReflectionException
43
     * @throws \SfCod\EmailEngineBundle\Exception\RepositoryUnavailableException
44
     * @throws \Throwable
45
     */
46
    public function testBody()
47
    {
48
        $text = uniqid('content_');
49
50
        $repository = $this->mockRepository();
51
52
        $content = $repository->getBodyTemplate([
53
            'message' => $text,
54
        ]);
55
56
        $this->assertEquals($text, $content);
57
    }
58
59
    /**
60
     * Test sender name
61
     *
62
     * @throws \ReflectionException
63
     * @throws \SfCod\EmailEngineBundle\Exception\RepositoryUnavailableException
64
     * @throws \Throwable
65
     */
66
    public function testSenderName()
67
    {
68
        $text = uniqid('content_');
69
70
        $repository = $this->mockRepository();
71
72
        $senderName = $repository->getSenderNameTemplate([
73
            'sender_name' => $text,
74
        ]);
75
76
        $this->assertEquals($text, $senderName);
77
    }
78
79
    /**
80
     * Test sender email
81
     *
82
     * @throws \ReflectionException
83
     * @throws \SfCod\EmailEngineBundle\Exception\RepositoryUnavailableException
84
     * @throws \Throwable
85
     */
86
    public function testSenderEmail()
87
    {
88
        $repository = $this->mockRepository();
89
90
        $senderEmail = $repository->getSenderEmailTemplate([]);
91
92
        $this->assertEquals('[email protected]', $senderEmail);
93
    }
94
95
    /**
96
     * Mock repository
97
     *
98
     * @return TwigFileRepository
99
     *
100
     * @throws \ReflectionException
101
     * @throws \SfCod\EmailEngineBundle\Exception\RepositoryUnavailableException
102
     */
103
    private function mockRepository(): TwigFileRepository
104
    {
105
        $template = new TestEmailTemplate(new TestEmailOptions('message', 'filepath'));
106
107
        $filePath = (new \ReflectionClass(get_class($template)))->getFileName();
108
        $directory = dirname($filePath);
109
110
        $repository = new TwigFileRepository(new \Twig_Environment(new \Twig_Loader_Chain([
111
            new \Twig_Loader_Filesystem('Data', $directory),
112
        ])));
113
        $repository->connect($template);
114
115
        return $repository;
116
    }
117
}
118