1
|
|
|
<?php |
2
|
|
|
namespace AcMailerTest\Options; |
3
|
|
|
|
4
|
|
|
use AcMailer\Options\AttachmentsOptions; |
5
|
|
|
use AcMailer\Options\BodyOptions; |
6
|
|
|
use AcMailer\Options\MessageOptions; |
7
|
|
|
use PHPUnit_Framework_TestCase as TestCase; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class MessageOptionsTest |
11
|
|
|
* @author Alejandro Celaya Alastrué |
12
|
|
|
* @link http://www.alejandrocelaya.com |
13
|
|
|
*/ |
14
|
|
|
class MessageOptionsTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var MessageOptions |
18
|
|
|
*/ |
19
|
|
|
protected $messageOptions; |
20
|
|
|
|
21
|
|
|
public function setUp() |
22
|
|
|
{ |
23
|
|
|
$this->messageOptions = new MessageOptions(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testDefaultValues() |
27
|
|
|
{ |
28
|
|
|
$this->assertEquals('', $this->messageOptions->getFrom()); |
29
|
|
|
$this->assertEquals('', $this->messageOptions->getFromName()); |
30
|
|
|
$this->assertEquals('', $this->messageOptions->getReplyTo()); |
31
|
|
|
$this->assertEquals('', $this->messageOptions->getReplyToName()); |
32
|
|
|
$this->assertEquals([], $this->messageOptions->getTo()); |
33
|
|
|
$this->assertEquals([], $this->messageOptions->getCc()); |
34
|
|
|
$this->assertEquals([], $this->messageOptions->getBcc()); |
35
|
|
|
$this->assertEquals('', $this->messageOptions->getSubject()); |
36
|
|
|
$this->assertInstanceOf('AcMailer\Options\BodyOptions', $this->messageOptions->getBody()); |
37
|
|
|
$this->assertInstanceOf('AcMailer\Options\AttachmentsOptions', $this->messageOptions->getAttachments()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testSetBody() |
41
|
|
|
{ |
42
|
|
|
$expected = new BodyOptions(); |
43
|
|
|
$this->assertSame($this->messageOptions, $this->messageOptions->setBody($expected)); |
44
|
|
|
$this->assertSame($expected, $this->messageOptions->getBody()); |
45
|
|
|
|
46
|
|
|
$this->messageOptions->setBody([]); |
47
|
|
|
$this->assertInstanceOf('AcMailer\Options\BodyOptions', $this->messageOptions->getBody()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testSetAttachments() |
51
|
|
|
{ |
52
|
|
|
$expected = new AttachmentsOptions(); |
53
|
|
|
$this->assertSame($this->messageOptions, $this->messageOptions->setAttachments($expected)); |
54
|
|
|
$this->assertSame($expected, $this->messageOptions->getAttachments()); |
55
|
|
|
|
56
|
|
|
$this->messageOptions->setAttachments([]); |
57
|
|
|
$this->assertInstanceOf('AcMailer\Options\AttachmentsOptions', $this->messageOptions->getAttachments()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @expectedException \AcMailer\Exception\InvalidArgumentException |
62
|
|
|
*/ |
63
|
|
|
public function testInvalidBodyThrowsException() |
64
|
|
|
{ |
65
|
|
|
$this->messageOptions->setBody(new \stdClass()); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @expectedException \AcMailer\Exception\InvalidArgumentException |
70
|
|
|
*/ |
71
|
|
|
public function testInvalidAttachmentsThrowException() |
72
|
|
|
{ |
73
|
|
|
$this->messageOptions->setAttachments('foo'); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
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: