|
1
|
|
|
<?php |
|
2
|
|
|
namespace AcMailerTest\Options; |
|
3
|
|
|
|
|
4
|
|
|
use AcMailer\Options\MailOptions; |
|
5
|
|
|
use AcMailer\Options\MessageOptions; |
|
6
|
|
|
use PHPUnit_Framework_TestCase as TestCase; |
|
7
|
|
|
use Zend\Mail\Transport\File; |
|
8
|
|
|
use Zend\Mail\Transport\FileOptions; |
|
9
|
|
|
use Zend\Mail\Transport\Sendmail; |
|
10
|
|
|
use Zend\Mail\Transport\Smtp; |
|
11
|
|
|
use Zend\Mail\Transport\SmtpOptions; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Mail options test case |
|
15
|
|
|
* @author Alejandro Celaya Alastrué |
|
16
|
|
|
* @link http://www.alejandrocelaya.com |
|
17
|
|
|
*/ |
|
18
|
|
|
class MailOptionsTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var MailOptions |
|
22
|
|
|
*/ |
|
23
|
|
|
private $mailOptions; |
|
24
|
|
|
|
|
25
|
|
|
public function setUp() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->mailOptions = new MailOptions([]); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testDefaultMailOptionsValues() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->assertEquals('\Zend\Mail\Transport\Sendmail', $this->mailOptions->getMailAdapter()); |
|
33
|
|
|
$this->assertEquals('\Zend\Mail\Transport\Sendmail', $this->mailOptions->getTransport()); |
|
34
|
|
|
$this->assertInstanceOf('AcMailer\Options\MessageOptions', $this->mailOptions->getMessageOptions()); |
|
35
|
|
|
$this->assertInstanceOf('Zend\Mail\Transport\SmtpOptions', $this->mailOptions->getSmtpOptions()); |
|
36
|
|
|
$this->assertInstanceOf('Zend\Mail\Transport\FileOptions', $this->mailOptions->getFileOptions()); |
|
37
|
|
|
$this->assertEquals([], $this->mailOptions->getMailListeners()); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testMailAdapterNameConversion() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->mailOptions->setMailAdapter('Sendmail'); |
|
43
|
|
|
$this->assertEquals('\Zend\Mail\Transport\Sendmail', $this->mailOptions->getMailAdapter()); |
|
44
|
|
|
|
|
45
|
|
|
$this->mailOptions->setMailAdapter('smtp'); |
|
46
|
|
|
$this->assertEquals('\Zend\Mail\Transport\Smtp', $this->mailOptions->getMailAdapter()); |
|
47
|
|
|
|
|
48
|
|
|
$this->mailOptions->setMailAdapter('FILE'); |
|
49
|
|
|
$this->assertEquals('\Zend\Mail\Transport\File', $this->mailOptions->getMailAdapter()); |
|
50
|
|
|
|
|
51
|
|
|
$nullAdapter = class_exists('Zend\Mail\Transport\InMemory') |
|
52
|
|
|
? '\Zend\Mail\Transport\InMemory' |
|
53
|
|
|
: '\Zend\Mail\Transport\Null'; |
|
54
|
|
|
$this->mailOptions->setMailAdapter('null'); |
|
55
|
|
|
$this->assertEquals($nullAdapter, $this->mailOptions->getMailAdapter()); |
|
56
|
|
|
|
|
57
|
|
|
$this->mailOptions->setMailAdapter('in_memory'); |
|
58
|
|
|
$this->assertEquals($nullAdapter, $this->mailOptions->getMailAdapter()); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testSetTransport() |
|
62
|
|
|
{ |
|
63
|
|
|
$transport = 'file'; |
|
64
|
|
|
$this->assertSame($this->mailOptions, $this->mailOptions->setTransport($transport)); |
|
65
|
|
|
$this->assertEquals('\Zend\Mail\Transport\File', $this->mailOptions->getTransport()); |
|
66
|
|
|
$this->assertEquals('\Zend\Mail\Transport\File', $this->mailOptions->getMailAdapter()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testSetMessageOptions() |
|
70
|
|
|
{ |
|
71
|
|
|
$expected = new MessageOptions(); |
|
72
|
|
|
$this->assertSame($this->mailOptions, $this->mailOptions->setMessageOptions($expected)); |
|
73
|
|
|
$this->assertSame($expected, $this->mailOptions->getMessageOptions()); |
|
74
|
|
|
|
|
75
|
|
|
$this->mailOptions->setMessageOptions([]); |
|
76
|
|
|
$this->assertInstanceOf('AcMailer\Options\MessageOptions', $this->mailOptions->getMessageOptions()); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @expectedException \AcMailer\Exception\InvalidArgumentException |
|
81
|
|
|
*/ |
|
82
|
|
|
public function testSetMessageOptionWithInvalidValueThrowsException() |
|
83
|
|
|
{ |
|
84
|
|
|
$this->mailOptions->setMessageOptions(new \stdClass()); |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function testSetSmtpOptions() |
|
88
|
|
|
{ |
|
89
|
|
|
$expected = new SmtpOptions(); |
|
90
|
|
|
$this->assertSame($this->mailOptions, $this->mailOptions->setSmtpOptions($expected)); |
|
91
|
|
|
$this->assertSame($expected, $this->mailOptions->getSmtpOptions()); |
|
92
|
|
|
|
|
93
|
|
|
$this->mailOptions->setSmtpOptions([]); |
|
94
|
|
|
$this->assertInstanceOf('Zend\Mail\Transport\SmtpOptions', $this->mailOptions->getSmtpOptions()); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @expectedException \AcMailer\Exception\InvalidArgumentException |
|
99
|
|
|
*/ |
|
100
|
|
|
public function testSetSmtpOptionWithInvalidValueThrowsException() |
|
101
|
|
|
{ |
|
102
|
|
|
$this->mailOptions->setSmtpOptions(new \stdClass()); |
|
|
|
|
|
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function testSetFileOptions() |
|
106
|
|
|
{ |
|
107
|
|
|
$expected = new FileOptions(); |
|
108
|
|
|
$this->assertSame($this->mailOptions, $this->mailOptions->setFileOptions($expected)); |
|
109
|
|
|
$this->assertSame($expected, $this->mailOptions->getFileOptions()); |
|
110
|
|
|
|
|
111
|
|
|
$this->mailOptions->setFileOptions([]); |
|
112
|
|
|
$this->assertInstanceOf('Zend\Mail\Transport\FileOptions', $this->mailOptions->getFileOptions()); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @expectedException \AcMailer\Exception\InvalidArgumentException |
|
117
|
|
|
*/ |
|
118
|
|
|
public function testSetFileOptionWithInvalidValueThrowsException() |
|
119
|
|
|
{ |
|
120
|
|
|
$this->mailOptions->setFileOptions(new \stdClass()); |
|
|
|
|
|
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function testSetMailListeners() |
|
124
|
|
|
{ |
|
125
|
|
|
$this->assertCount(0, $this->mailOptions->getMailListeners()); |
|
126
|
|
|
$this->assertSame($this->mailOptions, $this->mailOptions->setMailListeners([1, 2, 3])); |
|
127
|
|
|
$this->assertCount(3, $this->mailOptions->getMailListeners()); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function testSetRenderer() |
|
131
|
|
|
{ |
|
132
|
|
|
$this->assertEquals('mailviewrenderer', $this->mailOptions->getRenderer()); |
|
133
|
|
|
$this->assertSame($this->mailOptions, $this->mailOptions->setRenderer('foo')); |
|
134
|
|
|
$this->assertEquals('foo', $this->mailOptions->getRenderer()); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: