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
|
|
|
|