|
1
|
|
|
<?php |
|
2
|
|
|
namespace Mezon\Pop3\Tests; |
|
3
|
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
|
5
|
|
|
use Mezon\Pop3\Client; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* |
|
9
|
|
|
* @psalm-suppress PropertyNotSetInConstructor |
|
10
|
|
|
*/ |
|
11
|
|
|
class Pop3ClientUnitTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Email server |
|
16
|
|
|
* |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
private $server = 'ssl://pop.yandex.ru'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Email login |
|
23
|
|
|
* |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
private $login = '[email protected]'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Email password |
|
30
|
|
|
* |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
private $password = 'pop3test'; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Login validation |
|
37
|
|
|
*/ |
|
38
|
|
|
public function testInvalidLogin(): void |
|
39
|
|
|
{ |
|
40
|
|
|
// setup |
|
41
|
|
|
$client = new Client(); |
|
42
|
|
|
|
|
43
|
|
|
// assertions |
|
44
|
|
|
$this->expectException(\Exception::class); |
|
45
|
|
|
|
|
46
|
|
|
// test body |
|
47
|
|
|
$client->connect($this->server, 'unexisting-1024', 'password', 5, 995); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Password validation |
|
52
|
|
|
*/ |
|
53
|
|
|
public function testInvalidPassword(): void |
|
54
|
|
|
{ |
|
55
|
|
|
// setup |
|
56
|
|
|
$client = new Client(); |
|
57
|
|
|
|
|
58
|
|
|
// assertions |
|
59
|
|
|
$this->expectException(\Exception::class); |
|
60
|
|
|
|
|
61
|
|
|
// test body |
|
62
|
|
|
$client->connect($this->server, $this->login, 'password', 5, 995); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Normal connect |
|
67
|
|
|
*/ |
|
68
|
|
|
public function testConnect(): void |
|
69
|
|
|
{ |
|
70
|
|
|
// setup |
|
71
|
|
|
$client = new Client(); |
|
72
|
|
|
|
|
73
|
|
|
// test body |
|
74
|
|
|
$client->connect($this->server, $this->login, $this->password, 5, 995); |
|
75
|
|
|
|
|
76
|
|
|
// assertions |
|
77
|
|
|
$this->assertTrue(true); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Get emails count |
|
82
|
|
|
*/ |
|
83
|
|
|
public function testGetCount(): void |
|
84
|
|
|
{ |
|
85
|
|
|
$client = new Client($this->server, $this->login, $this->password, 5, 995); |
|
86
|
|
|
|
|
87
|
|
|
$this->assertGreaterThan(0, $client->getCount(), 'No emails were fetched'); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Get emails headers |
|
92
|
|
|
*/ |
|
93
|
|
|
public function testGetHeaders(): void |
|
94
|
|
|
{ |
|
95
|
|
|
$client = new Client($this->server, $this->login, $this->password, 5, 995); |
|
96
|
|
|
|
|
97
|
|
|
$headers = $client->getMessageHeaders(1); |
|
98
|
|
|
|
|
99
|
|
|
$this->assertStringNotContainsString($headers, 'From: ', 'No "From" header'); |
|
100
|
|
|
$this->assertStringNotContainsString($headers, 'To: ', 'No "To" header'); |
|
101
|
|
|
$this->assertStringNotContainsString($headers, 'Subject: ', 'No "Subject" header'); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Delete email |
|
106
|
|
|
*/ |
|
107
|
|
|
public function testDeleteEmail(): void |
|
108
|
|
|
{ |
|
109
|
|
|
$client = new Client($this->server, $this->login, $this->password, 5, 995); |
|
110
|
|
|
|
|
111
|
|
|
$headers = $client->getMessageHeaders(1); |
|
112
|
|
|
|
|
113
|
|
|
$messageId = Client::getMessageId($headers); |
|
114
|
|
|
|
|
115
|
|
|
$client->deleteMessage(1); |
|
116
|
|
|
|
|
117
|
|
|
$client->quit(); |
|
118
|
|
|
|
|
119
|
|
|
$client->connect($this->server, $this->login, $this->password, 5, 995); |
|
120
|
|
|
|
|
121
|
|
|
$headers = $client->getMessageHeaders(1); |
|
122
|
|
|
|
|
123
|
|
|
$messageId2 = Client::getMessageId($headers); |
|
124
|
|
|
|
|
125
|
|
|
$this->assertNotEquals($messageId, $messageId2, 'Message was not deleted'); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Testing getMessageSubject method |
|
130
|
|
|
*/ |
|
131
|
|
|
public function testGetMessageSubject(): void |
|
132
|
|
|
{ |
|
133
|
|
|
// setup |
|
134
|
|
|
$client = new Client($this->server, $this->login, $this->password, 5, 995); |
|
135
|
|
|
|
|
136
|
|
|
// test body |
|
137
|
|
|
$subject = $client->getMessageSubject(1); |
|
138
|
|
|
|
|
139
|
|
|
// assertions |
|
140
|
|
|
$this->assertNotEmpty($subject); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|