Completed
Push — develop ( f3c189...e92436 )
by Alejandro
08:55
created

testInvalidAttachmentsThrowException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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());
0 ignored issues
show
Documentation introduced by
new \stdClass() is of type object<stdClass>, but the function expects a object<AcMailer\Options\BodyOptions>|array.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
66
    }
67
68
    /**
69
     * @expectedException \AcMailer\Exception\InvalidArgumentException
70
     */
71
    public function testInvalidAttachmentsThrowException()
72
    {
73
        $this->messageOptions->setAttachments('foo');
0 ignored issues
show
Documentation introduced by
'foo' is of type string, but the function expects a object<AcMailer\Options\AttachmentsOptions>|array.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
74
    }
75
}
76