1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace AcMailerTest\Model; |
5
|
|
|
|
6
|
|
|
use AcMailer\Exception\InvalidArgumentException; |
7
|
|
|
use AcMailer\Model\Email; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use Zend\Mime\Part; |
10
|
|
|
|
11
|
|
|
class EmailTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var Email |
15
|
|
|
*/ |
16
|
|
|
private $email; |
17
|
|
|
|
18
|
|
|
public function setUp() |
19
|
|
|
{ |
20
|
|
|
$this->email = new Email(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param $invalidBody |
25
|
|
|
* @test |
26
|
|
|
* @dataProvider provideInvalidBodies |
27
|
|
|
*/ |
28
|
|
|
public function setBodyThrowsExceptionIfValueIsNotValid($invalidBody) |
29
|
|
|
{ |
30
|
|
|
$this->expectException(InvalidArgumentException::class); |
31
|
|
|
$this->email->setBody($invalidBody); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function provideInvalidBodies(): array |
35
|
|
|
{ |
36
|
|
|
return [ |
37
|
|
|
[null], |
38
|
|
|
[new \stdClass()], |
39
|
|
|
[new \Exception()], |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param array $invalidAttachments |
45
|
|
|
* @test |
46
|
|
|
* @dataProvider provideInvalidAttachments |
47
|
|
|
*/ |
48
|
|
|
public function setInvalidAttachmentsThrowsException(array $invalidAttachments) |
49
|
|
|
{ |
50
|
|
|
$this->expectException(InvalidArgumentException::class); |
51
|
|
|
$this->email->setAttachments($invalidAttachments); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function provideInvalidAttachments(): array |
55
|
|
|
{ |
56
|
|
|
return [ |
57
|
|
|
[['foo', null]], |
58
|
|
|
[[new \stdClass()]], |
59
|
|
|
[[new Part(), 5]], |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @test |
65
|
|
|
*/ |
66
|
|
|
public function providedNamesAreSavedForAttachments() |
67
|
|
|
{ |
68
|
|
|
$this->email->addAttachments([ |
69
|
|
|
'foo' => __FILE__, |
70
|
|
|
]); |
71
|
|
|
|
72
|
|
|
$this->assertArrayHasKey('foo', $this->email->getAttachments()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @test |
77
|
|
|
*/ |
78
|
|
|
public function attachmentsAreProperlyComputed() |
79
|
|
|
{ |
80
|
|
|
$this->email->addAttachment(__DIR__ . '/../attachments/file1'); |
81
|
|
|
$this->email->addAttachment(__DIR__ . '/../attachments/file2'); |
82
|
|
|
$this->email->setAttachmentsDir([ |
83
|
|
|
'path' => __DIR__ . '/../attachments/dir', |
84
|
|
|
'recursive' => true, |
85
|
|
|
]); |
86
|
|
|
|
87
|
|
|
$computed = $this->email->getComputedAttachments(); |
88
|
|
|
|
89
|
|
|
$this->assertCount(4, $computed); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|