-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSenderTest.php
More file actions
84 lines (74 loc) · 2.48 KB
/
SenderTest.php
File metadata and controls
84 lines (74 loc) · 2.48 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
<?php declare(strict_types=1);
namespace Tests\Mail;
use PHPUnit\Framework\TestCase;
/**
* 测试 php-mailer\Mail\Sender
*
* @author fdipzone
*/
final class SenderTest extends TestCase
{
/**
* @covers \Mail\Sender::__construct
*/
public function testConstruct()
{
$from_email = 'technology@zone.com';
$from_name = 'fdipzone';
$sender_email = 'promotion@zone.com';
$sender = new \Mail\Sender($from_email, $from_name, $sender_email);
$this->assertEquals('Mail\Sender', get_class($sender));
}
/**
* @covers \Mail\Sender::__construct
*/
public function testConstructFromEmailEmptyException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('mailer sender: from email is empty');
$from_email = '';
new \Mail\Sender($from_email);
}
/**
* @covers \Mail\Sender::__construct
*/
public function testConstructFromEmailInvalidException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('mailer sender: from email is invalid');
$from_email = 'good@good';
new \Mail\Sender($from_email);
}
/**
* @covers \Mail\Sender::__construct
*/
public function testConstructSenderEmailInvalidException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('mailer sender: sender email is invalid');
$from_email = 'technology@zone.com';
$sender_email = 'good@good';
new \Mail\Sender($from_email, '', $sender_email);
}
/**
* @covers \Mail\Sender::__construct
* @covers \Mail\Sender::fromEmail
* @covers \Mail\Sender::fromName
* @covers \Mail\Sender::senderEmail
*/
public function testGet()
{
$from_email = 'technology@zone.com';
$from_name = 'fdipzone';
$sender_email = 'promotion@zone.com';
$sender = new \Mail\Sender($from_email, $from_name, $sender_email);
$this->assertEquals($from_email, $sender->fromEmail());
$this->assertEquals($from_name, $sender->fromName());
$this->assertEquals($sender_email, $sender->senderEmail());
// 测试不设置发件人名称与发件人电子邮箱
$sender = new \Mail\Sender($from_email);
$this->assertEquals($from_email, $sender->fromEmail());
$this->assertEquals($from_email, $sender->fromName());
$this->assertEquals('', $sender->senderEmail());
}
}