SMTPClientCest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 37
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A sendSMTPMessage() 0 50 3
1
<?php
2
3
namespace Kodus\Mail\Test\Integration;
4
5
use IntegrationTester;
6
use Kodus\Mail\Test\Mocks\MockLogger;
7
8
class SMTPClientCest
9
{
10
    /**
11
     * In this test, we use the SMTP Client at a low level, without involving the
12
     * Mail Service or MIME Writer - we connect using a plain socket without authentication.
13
     */
14
    public function sendSMTPMessage(IntegrationTester $I)
15
    {
16
        $connector = $I->createSocketConnector();
17
18
        $client = $connector->connect("localhost");
19
20
        $logger = new MockLogger();
21
22
        $client->setLogger($logger);
23
24
        $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");
25
26
        $mime_message = <<<EOT
27
Date: Thu, 15 Sep 2016 17:20:54 +0200
28
To: =?utf-8?q?Rasmus =C3=A5h Schultz?= <[email protected]>
29
From: [email protected]
30
Subject: =?UTF-8?Q?Hey, Rasmus! I like =C3=86=C3=98=C3=85=C3=A6=C3=B8=C3=A5!?=
31
MIME-Version: 1.0
32
Content-Type: text/plain; charset=UTF-8
33
Content-Transfer-Encoding: quoted-printable
34
35
{$quoted_body}
36
EOT;
37
38
        $client->sendMail(
39
            "[email protected]",
40
            ["[email protected]"],
41
            function ($resource) use ($mime_message) {
42
                fwrite($resource, $mime_message);
43
            }
44
        );
45
46
        $expected = [
47
            'S: MAIL FROM:<[email protected]>',
48
            '/R: 250.*/',
49
            'S: RCPT TO:<[email protected]>',
50
            '/R: 250.*/',
51
            'S: DATA',
52
            '/R: 354.*/',
53
            "S: \r\n.",
54
            '/R: 250.*/',
55
        ];
56
57
        $records = $logger->records;
58
59
        foreach ($expected as $index => $entry) {
60
            if (substr($entry, 0, 1) === "/") {
61
                $I->assertRegExp($entry, $records[$index]);
62
            } else {
63
                $I->assertSame($entry, $records[$index]);
64
            }
65
        }
66
    }
67
}
68