-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerConfigTest.php
More file actions
146 lines (122 loc) · 4.6 KB
/
ServerConfigTest.php
File metadata and controls
146 lines (122 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php declare(strict_types=1);
namespace Tests\Mail;
use PHPUnit\Framework\TestCase;
/**
* 测试 php-mailer\Mail\ServerConfig
*
* @author fdipzone
*/
final class ServerConfigTest extends TestCase
{
/**
* @covers \Mail\ServerConfig::__construct
*/
public function testConstruct()
{
$smtp_host = 'smtp.mxhichina.com';
$smtp_username = 'fdipzone';
$smtp_password = '123456abc!@#$';
$server_config = new \Mail\ServerConfig($smtp_host, $smtp_username, $smtp_password);
$this->assertEquals('Mail\ServerConfig', get_class($server_config));
}
/**
* @covers \Mail\ServerConfig::__construct
*/
public function testConstructSmtpHostException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('mailer server config: smtp host is empty');
$smtp_host = '';
$smtp_username = 'fdipzone';
$smtp_password = '123456abc!@#$';
new \Mail\ServerConfig($smtp_host, $smtp_username, $smtp_password);
}
/**
* @covers \Mail\ServerConfig::__construct
*/
public function testConstructSmtpUsernameException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('mailer server config: smtp username is empty');
$smtp_host = 'smtp.mxhichina.com';
$smtp_username = '';
$smtp_password = '123456abc!@#$';
new \Mail\ServerConfig($smtp_host, $smtp_username, $smtp_password);
}
/**
* @covers \Mail\ServerConfig::__construct
*/
public function testConstructSmtpPasswordException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('mailer server config: smtp password is empty');
$smtp_host = 'smtp.mxhichina.com';
$smtp_username = 'fdipzone';
$smtp_password = '';
new \Mail\ServerConfig($smtp_host, $smtp_username, $smtp_password);
}
/**
* @covers \Mail\ServerConfig
*/
public function testSetAndGet()
{
$smtp_host = 'smtp.mxhichina.com';
$smtp_port = 465;
$smtp_secure = 'ssl';
$smtp_auth = true;
$smtp_username = 'fdipzone';
$smtp_password = '123456abc!@#$';
$smtp_debug = false;
$server_config = new \Mail\ServerConfig($smtp_host, $smtp_username, $smtp_password);
$server_config->setSmtpPort($smtp_port);
$server_config->setSmtpSecure($smtp_secure);
$server_config->setSmtpAuth($smtp_auth);
$server_config->setSmtpDebug($smtp_debug);
$this->assertEquals($smtp_host, $server_config->smtpHost());
$this->assertEquals($smtp_port, $server_config->smtpPort());
$this->assertEquals($smtp_secure, $server_config->smtpSecure());
$this->assertEquals($smtp_auth, $server_config->smtpAuth());
$this->assertEquals($smtp_username, $server_config->smtpUsername());
$this->assertEquals($smtp_password, $server_config->smtpPassword());
$this->assertEquals($smtp_debug, $server_config->smtpDebug());
}
/**
* @covers \Mail\ServerConfig::setSmtpPort
*/
public function testSetSmtpPortLowerLimitException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('mailer server config: port must be between 0 and 65535');
$smtp_host = 'smtp.mxhichina.com';
$smtp_username = 'fdipzone';
$smtp_password = '123456abc!@#$';
$server_config = new \Mail\ServerConfig($smtp_host, $smtp_username, $smtp_password);
$server_config->setSmtpPort(-1);
}
/**
* @covers \Mail\ServerConfig::setSmtpPort
*/
public function testSetSmtpPortUpperLimitException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('mailer server config: port must be between 0 and 65535');
$smtp_host = 'smtp.mxhichina.com';
$smtp_username = 'fdipzone';
$smtp_password = '123456abc!@#$';
$server_config = new \Mail\ServerConfig($smtp_host, $smtp_username, $smtp_password);
$server_config->setSmtpPort(65536);
}
/**
* @covers \Mail\ServerConfig::setSmtpSecure
*/
public function testSetSmtpSecureException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('mailer server config: smtp secure is empty');
$smtp_host = 'smtp.mxhichina.com';
$smtp_username = 'fdipzone';
$smtp_password = '123456abc!@#$';
$server_config = new \Mail\ServerConfig($smtp_host, $smtp_username, $smtp_password);
$server_config->setSmtpSecure('');
}
}