1 | <?php |
||||
2 | /** |
||||
3 | * File: TransactionalEmailHandlerTest.php |
||||
4 | * |
||||
5 | * @author Maciej Sławik <[email protected]> |
||||
6 | * Github: https://github.com/maciejslawik |
||||
7 | */ |
||||
8 | |||||
9 | namespace MSlwk\FreshMail\Test\Message; |
||||
10 | |||||
11 | use MSlwk\FreshMail\Handler\Message\TransactionalEmailHandler; |
||||
12 | use MSlwk\FreshMail\Tests\BaseTest; |
||||
13 | use PHPUnit\Framework\TestCase; |
||||
14 | use MSlwk\FreshMail\Error\ErrorHandler; |
||||
15 | use MSlwk\FreshMail\Exception\Message\FreshMailTransactionalEmailException; |
||||
16 | |||||
17 | /** |
||||
18 | * Class TransactionalEmailHandlerTest |
||||
19 | * |
||||
20 | * @package MSlwk\FreshMail\Test\Message |
||||
21 | */ |
||||
22 | class TransactionalEmailHandlerTest extends TestCase |
||||
23 | { |
||||
24 | use BaseTest; |
||||
25 | |||||
26 | /** |
||||
27 | * @param $sendRequestReturnValue |
||||
28 | * @return \PHPUnit_Framework_MockObject_MockObject |
||||
0 ignored issues
–
show
|
|||||
29 | */ |
||||
30 | public function getTransactionalEmailHandlerMock($sendRequestReturnValue) |
||||
31 | { |
||||
32 | $transactionalEmailHandler = $this->getMockBuilder('\MSlwk\FreshMail\Handler\Message\TransactionalEmailHandler') |
||||
0 ignored issues
–
show
The function
PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||
33 | ->setConstructorArgs([new ErrorHandler(), '', '']) |
||||
34 | ->setMethods(['sendRequest']) |
||||
35 | ->getMock(); |
||||
36 | |||||
37 | $transactionalEmailHandler->expects($this->once()) |
||||
38 | ->method('sendRequest') |
||||
39 | ->will($this->returnValue($sendRequestReturnValue)); |
||||
40 | |||||
41 | return $transactionalEmailHandler; |
||||
0 ignored issues
–
show
|
|||||
42 | } |
||||
43 | |||||
44 | public function testEmailSuccessfullySent() |
||||
45 | { |
||||
46 | $transactionalEmailHandler = $this->getTransactionalEmailHandlerMock('{"status":"OK"}'); |
||||
47 | $returnValue = $transactionalEmailHandler->sendTransactionalEmail( |
||||
48 | '[email protected]', |
||||
49 | 'Email subject', |
||||
50 | 'Email content', |
||||
51 | '[email protected]', |
||||
52 | 'Sender', |
||||
53 | '[email protected]', |
||||
54 | 'UTF-8', |
||||
55 | 'http://attachment.com', |
||||
56 | 'tag', |
||||
57 | false, |
||||
58 | 'http://domain.com' |
||||
59 | ); |
||||
60 | self::assertNull($returnValue); |
||||
61 | } |
||||
62 | |||||
63 | public function testApiEndpoint() |
||||
64 | { |
||||
65 | $accountCreateHandler = new TransactionalEmailHandler(new ErrorHandler(), '', ''); |
||||
66 | $expectedApiEndpoint = '/rest/mail'; |
||||
67 | $returnedApiEndpoint = $this->getApiEndpoint($accountCreateHandler); |
||||
68 | self::assertEquals($expectedApiEndpoint, $returnedApiEndpoint); |
||||
69 | } |
||||
70 | |||||
71 | public function testWrongSubscriberEmail() |
||||
72 | { |
||||
73 | $transactionalEmailHandler = $this->getTransactionalEmailHandlerMock( |
||||
74 | '{"errors":[{ "message":"Wrong email address", "code":"1201" }], "status":"errors"}' |
||||
75 | ); |
||||
76 | $this->expectException(FreshMailTransactionalEmailException::class); |
||||
77 | $transactionalEmailHandler->sendTransactionalEmail('[email protected]', 'Email subject', 'Email content'); |
||||
78 | } |
||||
79 | |||||
80 | public function testNoEmailSubject() |
||||
81 | { |
||||
82 | $transactionalEmailHandler = $this->getTransactionalEmailHandlerMock( |
||||
83 | '{"errors":[{ "message":"Email subject missing", "code":"1202" }], "status":"errors"}' |
||||
84 | ); |
||||
85 | $this->expectException(FreshMailTransactionalEmailException::class); |
||||
86 | $transactionalEmailHandler->sendTransactionalEmail('[email protected]', 'Email subject', 'Email content'); |
||||
87 | } |
||||
88 | |||||
89 | public function testNoEmailContent() |
||||
90 | { |
||||
91 | $transactionalEmailHandler = $this->getTransactionalEmailHandlerMock( |
||||
92 | '{"errors":[{ "message":"Email content missing", "code":"1203" }], "status":"errors"}' |
||||
93 | ); |
||||
94 | $this->expectException(FreshMailTransactionalEmailException::class); |
||||
95 | $transactionalEmailHandler->sendTransactionalEmail('[email protected]', 'Email subject', 'Email content'); |
||||
96 | } |
||||
97 | |||||
98 | public function testWrongReplyToAddress() |
||||
99 | { |
||||
100 | $transactionalEmailHandler = $this->getTransactionalEmailHandlerMock( |
||||
101 | '{"errors":[{ "message":"Wrong replyTo email address", "code":"1204" }], "status":"errors"}' |
||||
102 | ); |
||||
103 | $this->expectException(FreshMailTransactionalEmailException::class); |
||||
104 | $transactionalEmailHandler->sendTransactionalEmail('[email protected]', 'Email subject', 'Email content'); |
||||
105 | } |
||||
106 | |||||
107 | public function testWrongFromEmail() |
||||
108 | { |
||||
109 | $transactionalEmailHandler = $this->getTransactionalEmailHandlerMock( |
||||
110 | '{"errors":[{ "message":"Wrong from email", "code":"1205" }], "status":"errors"}' |
||||
111 | ); |
||||
112 | $this->expectException(FreshMailTransactionalEmailException::class); |
||||
113 | $transactionalEmailHandler->sendTransactionalEmail('[email protected]', 'Email subject', 'Email content'); |
||||
114 | } |
||||
115 | |||||
116 | public function testEmptyFromName() |
||||
117 | { |
||||
118 | $transactionalEmailHandler = $this->getTransactionalEmailHandlerMock( |
||||
119 | '{"errors":[{ "message":"From name cannot be empty", "code":"1206" }], "status":"errors"}' |
||||
120 | ); |
||||
121 | $this->expectException(FreshMailTransactionalEmailException::class); |
||||
122 | $transactionalEmailHandler->sendTransactionalEmail('[email protected]', 'Email subject', 'Email content'); |
||||
123 | } |
||||
124 | |||||
125 | public function testDailyLimitExceeded() |
||||
126 | { |
||||
127 | $transactionalEmailHandler = $this->getTransactionalEmailHandlerMock( |
||||
128 | '{"errors":[{ "message":"Daily limit exceeded", "code":"1207" }], "status":"errors"}' |
||||
129 | ); |
||||
130 | $this->expectException(FreshMailTransactionalEmailException::class); |
||||
131 | $transactionalEmailHandler->sendTransactionalEmail('[email protected]', 'Email subject', 'Email content'); |
||||
132 | } |
||||
133 | |||||
134 | public function testUnsupportedEncoding() |
||||
135 | { |
||||
136 | $transactionalEmailHandler = $this->getTransactionalEmailHandlerMock( |
||||
137 | '{"errors":[{ "message":"Unsupported encoding", "code":"1208" }], "status":"errors"}' |
||||
138 | ); |
||||
139 | $this->expectException(FreshMailTransactionalEmailException::class); |
||||
140 | $transactionalEmailHandler->sendTransactionalEmail('[email protected]', 'Email subject', 'Email content'); |
||||
141 | } |
||||
142 | |||||
143 | public function testIncorrectAttachmentUrl() |
||||
144 | { |
||||
145 | $transactionalEmailHandler = $this->getTransactionalEmailHandlerMock( |
||||
146 | '{"errors":[{ "message":"Wrong attachment URL", "code":"1209" }], "status":"errors"}' |
||||
147 | ); |
||||
148 | $this->expectException(FreshMailTransactionalEmailException::class); |
||||
149 | $transactionalEmailHandler->sendTransactionalEmail('[email protected]', 'Email subject', 'Email content'); |
||||
150 | } |
||||
151 | |||||
152 | public function testAttachmentDoesntExist() |
||||
153 | { |
||||
154 | $transactionalEmailHandler = $this->getTransactionalEmailHandlerMock( |
||||
155 | '{"errors":[{ "message":"Attachment does not exist", "code":"1210" }], "status":"errors"}' |
||||
156 | ); |
||||
157 | $this->expectException(FreshMailTransactionalEmailException::class); |
||||
158 | $transactionalEmailHandler->sendTransactionalEmail('[email protected]', 'Email subject', 'Email content'); |
||||
159 | } |
||||
160 | |||||
161 | public function testMaxAttachmentSizeExceeded() |
||||
162 | { |
||||
163 | $transactionalEmailHandler = $this->getTransactionalEmailHandlerMock( |
||||
164 | '{"errors":[{ "message":"Maximum attachment size exceeded", "code":"1211" }], "status":"errors"}' |
||||
165 | ); |
||||
166 | $this->expectException(FreshMailTransactionalEmailException::class); |
||||
167 | $transactionalEmailHandler->sendTransactionalEmail('[email protected]', 'Email subject', 'Email content'); |
||||
168 | } |
||||
169 | |||||
170 | public function testIncorrectRebrandingDomain() |
||||
171 | { |
||||
172 | $transactionalEmailHandler = $this->getTransactionalEmailHandlerMock( |
||||
173 | '{"errors":[{ "message":"Incorrect rebranding domain", "code":"1212" }], "status":"errors"}' |
||||
174 | ); |
||||
175 | $this->expectException(FreshMailTransactionalEmailException::class); |
||||
176 | $transactionalEmailHandler->sendTransactionalEmail('[email protected]', 'Email subject', 'Email content'); |
||||
177 | } |
||||
178 | |||||
179 | public function testIncorrectCampaignTag() |
||||
180 | { |
||||
181 | $transactionalEmailHandler = $this->getTransactionalEmailHandlerMock( |
||||
182 | '{"errors":[{ "message":"Incorrect campaign tag", "code":"1213" }], "status":"errors"}' |
||||
183 | ); |
||||
184 | $this->expectException(FreshMailTransactionalEmailException::class); |
||||
185 | $transactionalEmailHandler->sendTransactionalEmail('[email protected]', 'Email subject', 'Email content'); |
||||
186 | } |
||||
187 | |||||
188 | public function testSystemError() |
||||
189 | { |
||||
190 | $transactionalEmailHandler = $this->getTransactionalEmailHandlerMock( |
||||
191 | '{"errors":[{ "message":"System error occurred", "code":"1250" }], "status":"errors"}' |
||||
192 | ); |
||||
193 | $this->expectException(FreshMailTransactionalEmailException::class); |
||||
194 | $transactionalEmailHandler->sendTransactionalEmail('[email protected]', 'Email subject', 'Email content'); |
||||
195 | } |
||||
196 | |||||
197 | public function testSubscriberEmailBlocked() |
||||
198 | { |
||||
199 | $transactionalEmailHandler = $this->getTransactionalEmailHandlerMock( |
||||
200 | '{"errors":[{ "message":"The email address is blocked", "code":"1251" }], "status":"errors"}' |
||||
201 | ); |
||||
202 | $this->expectException(FreshMailTransactionalEmailException::class); |
||||
203 | $transactionalEmailHandler->sendTransactionalEmail('[email protected]', 'Email subject', 'Email content'); |
||||
204 | } |
||||
205 | } |
||||
206 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths