-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttachmentTest.php
More file actions
84 lines (73 loc) · 2.22 KB
/
AttachmentTest.php
File metadata and controls
84 lines (73 loc) · 2.22 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\Attachment
*
* @author fdipzone
*/
final class AttachmentTest extends TestCase
{
// 定义用例用到的测试文件
private static $attachment_file = '/tmp/attachment.txt';
// 初始化测试文件
public static function setUpBeforeClass():void
{
file_put_contents(self::$attachment_file, 'attachment file');
}
// 删除测试文件
public static function tearDownAfterClass():void
{
if(file_exists(self::$attachment_file))
{
unlink(self::$attachment_file);
}
}
/**
* @covers \Mail\Attachment::__construct
*/
public function testConstruct()
{
$file = self::$attachment_file;
$name = '附件.txt';
$attachment = new \Mail\Attachment($file, $name);
$this->assertEquals('Mail\Attachment', get_class($attachment));
}
/**
* @covers \Mail\Attachment::__construct
*/
public function testConstructFileEmptyException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('mailer attachment: file is empty');
$file = '';
new \Mail\Attachment($file);
}
/**
* @covers \Mail\Attachment::__construct
*/
public function testConstructFileNotExistsException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('mailer attachment: file not exists');
$file = '/tmp/not_exists_file.txt';
new \Mail\Attachment($file);
}
/**
* @covers \Mail\Attachment::__construct
* @covers \Mail\Attachment::file
* @covers \Mail\Attachment::name
*/
public function testGet()
{
$file = self::$attachment_file;
$name = '附件.txt';
$attachment = new \Mail\Attachment($file, $name);
$this->assertEquals($file, $attachment->file());
$this->assertEquals($name, $attachment->name());
// 测试不设置附件名称
$attachment = new \Mail\Attachment($file);
$this->assertEquals($file, $attachment->file());
$this->assertEquals(basename($file), $attachment->name());
}
}