1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kodus\Mail\Test\Integration; |
4
|
|
|
|
5
|
|
|
use Codeception\Scenario; |
6
|
|
|
use IntegrationTester; |
7
|
|
|
use Kodus\Mail\SMTP\SMTPException; |
8
|
|
|
use Kodus\Mail\Test\Mocks\MockLogger; |
9
|
|
|
|
10
|
|
|
class SecureSocketCest |
11
|
|
|
{ |
12
|
|
|
public function sendSMTPMessageOverSecureSocket(IntegrationTester $I, Scenario $scenario) |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
$connector = $I->createSecureSocketConnector(); |
15
|
|
|
|
16
|
|
|
try { |
17
|
|
|
$client = $connector->connect("localhost"); |
18
|
|
|
} catch (SMTPException $exception) { |
19
|
|
|
$I->markTestSkipped(<<<EOT |
20
|
|
|
Make sure your SMTP server has a SSL certificate installed and that your system trusts it. |
21
|
|
|
[{$exception->getMessage()}] |
22
|
|
|
EOT); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
$logger = new MockLogger(); |
26
|
|
|
|
27
|
|
|
$client->setLogger($logger); |
28
|
|
|
|
29
|
|
|
$quoted_body = quoted_printable_encode("Hey, Bar!\r\n\r\nIt's me! Foo!\r\n\r\nHow you been man?\r\n\r\n.\r\n\r\n.foo!\r\n\r\nhehehe :-)\r\n\r\n"); |
30
|
|
|
|
31
|
|
|
$mime_message = <<<EOT |
32
|
|
|
Date: Thu, 15 Sep 2016 17:20:54 +0200 |
33
|
|
|
To: =?utf-8?q?Rasmus =C3=A5h Schultz?= <[email protected]> |
34
|
|
|
From: [email protected] |
35
|
|
|
Subject: =?UTF-8?Q?Hey, Rasmus! I like =C3=86=C3=98=C3=85=C3=A6=C3=B8=C3=A5!?= |
36
|
|
|
MIME-Version: 1.0 |
37
|
|
|
Content-Type: text/plain; charset=UTF-8 |
38
|
|
|
Content-Transfer-Encoding: quoted-printable |
39
|
|
|
|
40
|
|
|
$quoted_body |
41
|
|
|
EOT; |
42
|
|
|
|
43
|
|
|
$client->sendMail( |
44
|
|
|
"[email protected]", |
45
|
|
|
["[email protected]"], |
46
|
|
|
function ($resource) use ($mime_message) { |
47
|
|
|
fwrite($resource, $mime_message); |
48
|
|
|
} |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
$expected = [ |
52
|
|
|
'S: MAIL FROM:<[email protected]>', |
53
|
|
|
'/R: 250.*/', |
54
|
|
|
'S: RCPT TO:<[email protected]>', |
55
|
|
|
'/R: 250.*/', |
56
|
|
|
'S: DATA', |
57
|
|
|
'/R: 354.*/', |
58
|
|
|
"S: \r\n.", |
59
|
|
|
'/R: 250.*/', |
60
|
|
|
]; |
61
|
|
|
|
62
|
|
|
$records = $logger->records; |
63
|
|
|
|
64
|
|
|
foreach ($expected as $index => $entry) { |
65
|
|
|
if (substr($entry, 0, 1) === "/") { |
66
|
|
|
$I->assertRegExp($entry, $records[$index]); |
67
|
|
|
} else { |
68
|
|
|
$I->assertSame($entry, $records[$index]); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.